Mac keystrokes using the minDevkit
Trevor being Trevor
May 01 2023 | 11:51 pm
This post has a lot of information to give the necessary context, but essentially I can't get the project to build when I add the code to simulate a keystroke and I am not sure why. I was able to figure this out for Windows, but I am running into a problem on Mac that I can't get past. I followed the instructions of this video and github page which seem to be the most up to date.
https://www.youtube.com/watch?v=il5WblTBUgs
https://github.com/Cycling74/max-sdk/blob/main/README-8.2-update.md
I started by manipulating the min.hello-world project. I removed the greeting when the object loads, edited the bang function and created a function that responds to integers. Everything compiles and works as expected. However, I want to simulate a keystroke so I brought in the following libraries...
#include <CoreGraphics/CoreGraphics.h> #include <ApplicationServices/ApplicationServices.h> #include <Carbon/Carbon.h>
As far as I understand, I only need Application Services, but the other ones were added as I tried to troubleshoot issues. Anyway, to use those libraries I updated my "respond to integer" function to the following code...
message<> number {this, "int", MIN_FUNCTION { int key = 56; //EDIT: this code is close to correct, but definitely don't trust it. //there are better examples on Stack Overflow, if you are really stuck //comment and could share something better. Also, it appears //olsen put 11strokes code up on Github. It says it's cross platform, so it //may be a better and more comprehensive source than what I could offer. // Create an HID hardware event source CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); // Create a new keyboard key press event CGEventRef evt = CGEventCreateKeyboardEvent(src, (CGKeyCode) key, true); // Post keyboard event and release CGEventPost (kCGHIDEventTap, evt); CFRelease (evt); CFRelease (src); //this line printed before I added the above cout<< "Sometimes I work, sometimes I don't" << endl; return {}; } };
Instead of Xcode (I am not very familiar with it) I am using the terminal to build using the command "cmake --build ." inside the build folder which works great. However, the build fails once I add the keystroke specific code. This is the error given with crucial information in bold...
Undefined symbols for architecture x86_64: "_CFRelease", referenced from: hello_world::number::'lambda'(std::__1::vector<c74::min::atom, hello_world::number::allocator<c74::min>> const&, int)::operator()(std::__1::vector<c74::min::atom, hello_world::number::allocator<c74::min>> const, int) const in min.hello-world.o "_CGEventCreateKeyboardEvent", referenced from: hello_world::number::'lambda'(std::__1::vector<c74::min::atom, hello_world::number::allocator<c74::min>> const&, int)::operator()(std::__1::vector<c74::min::atom, hello_world::number::allocator<c74::min>> const, int) const in min.hello-world.o "_CGEventPost", referenced from: hello_world::number::'lambda'(std::__1::vector<c74::min::atom, hello_world::number::allocator<c74::min>> const&, int)::operator()(std::__1::vector<c74::min::atom, hello_world::number::allocator<c74::min>> const, int) const in min.hello-world.o "_CGEventSourceCreate", referenced from: hello_world::number::'lambda'(std::__1::vector<c74::min::atom, hello_world::number::allocator<c74::min>> const&, int)::operator()(std::__1::vector<c74::min::atom, hello_world::number::allocator<c74::min>> const, int) const in min.hello-world.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Even though it says the issue is for x86_64 I have seen it say arm64 instead as I've tried to get things working. For that reason, I don't think the issue is specific to the architecture, but I could be wrong. Also, Xcode intellisense autocompletes these symbols as I type them and I am able to right click and "Jump to Definition" so there is a clearly a path to these symbols, but apparently the linker or compiler is unaware of that path. To combat this (and an earlier issue), I tried updating the CMakeLists.txt for min.helloworld to the following...
# Copyright 2018 The Min-DevKit Authors. All rights reserved. # Use of this source code is governed by the MIT License found in the License.md file. cmake_minimum_required(VERSION 3.0) set(C74_MIN_API_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../min-api) include(${C74_MIN_API_DIR}/script/min-pretarget.cmake) ############################################################# # MAX EXTERNAL ############################################################# include_directories( "${C74_INCLUDES}" "/System/Library/Frameworks/CoreFoundation.framework/Headers" "/System/Library/Frameworks/ApplicationServices.framework/Headers" "/System/Library/Frameworks/Carbon.framework/Headers" "/System/Library/Frameworks/CoreGraphics.framework/Headers" ) set( SOURCE_FILES ${PROJECT_NAME}.cpp ) add_library( ${PROJECT_NAME} MODULE ${SOURCE_FILES} ) target_link_libraries( ${PROJECT_NAME} "${C74_LIBS}" "-framework CoreFoundation" "-framework ApplicationServices" "-framework Carbon" "-framework CoreGraphics" ) include(${C74_MIN_API_DIR}/script/min-posttarget.cmake) ############################################################# # UNIT TEST ############################################################# include(${C74_MIN_API_DIR}/test/min-object-unittest.cmake)
Lastly, in trying to figure this out I was made aware of the 11olsen 11strokes project. That could potentially work for me, but I've already built something specific on Windows and replicating it on Mac would be much less future headache if possible. Also, learning is fun most of the time haha.
Anyway I'm at the point where I don't know how to proceed. It's probably something simple, but this is a bit out of my element so I'm struggling to see it. Any advice or ideas are welcomed and greatly appreciated!
2021 Macbook Pro, M1 Pro, Ventura 13.3.1
cmake version 3.26.0
xcode version 14.3
max version 8.5.3
Let me know if you need anymore info!