相关疑难解决方法(0)

什么是Objective C++?

什么是Objective C++,我可以在Xcode中使用这种语言吗?

c++ xcode objective-c objective-c++

152
推荐指数
3
解决办法
7万
查看次数

使用IOHIDManager获取修饰键事件

我正在尝试使用IOHIDManager获取修饰键事件,因为Cocoa flagsChanged事件缺乏(难以区分按下/释放,左/右如果两者都关闭等)这里是我创建管理器并注册回调的代码.

IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault,
        kIOHIDOptionsTypeNone);
if (CFGetTypeID(hidManager) != IOHIDManagerGetTypeID())
    return 1;

CFMutableDictionaryRef capsLock =
    myCreateDeviceMatchingDictionary(0x07, 0x39);
CFMutableDictionaryRef lctrl =
    myCreateDeviceMatchingDictionary(0x07, 0xE0);
CFMutableDictionaryRef lshift =
    myCreateDeviceMatchingDictionary(0x07, 0xE1);
CFMutableDictionaryRef lalt =
    myCreateDeviceMatchingDictionary(0x07, 0xE2);
CFMutableDictionaryRef lsuper =
    myCreateDeviceMatchingDictionary(0x07, 0xE3);
CFMutableDictionaryRef rctrl =
    myCreateDeviceMatchingDictionary(0x07, 0xE4);
CFMutableDictionaryRef rshift =
    myCreateDeviceMatchingDictionary(0x07, 0xE5);
CFMutableDictionaryRef ralt =
    myCreateDeviceMatchingDictionary(0x07, 0xE6);
CFMutableDictionaryRef rsuper =
    myCreateDeviceMatchingDictionary(0x07, 0xE7);

CFMutableDictionaryRef matchesList[] = {
    capsLock,
    lctrl,
    lshift,
    lalt,
    lsuper,
    rctrl,
    rshift,
    ralt,
    rsuper
};
CFArrayRef matches = CFArrayCreate(kCFAllocatorDefault,
        (const void **)matchesList, 9, …
Run Code Online (Sandbox Code Playgroud)

keyboard macos iokit core-foundation

8
推荐指数
2
解决办法
4515
查看次数

使用C++从OSX中的HIDManager获取鼠标事件

我正在将游戏从PC移植到osx,而我却陷入了输入事件的困境.主游戏窗口是一个与C++后端接口的可可应用程序.pc代码使用DirectInput和Windows消息来生成游戏理解的键盘和鼠标事件.

当我第一次启动端口时,我用碳事件处理替换了Windows消息,但是因为发现Cocoa应用程序不会触发碳事件.我做了一些阅读并发现了HIDManager似乎做了我想要的,可以从c ++访问.使用此处帖子中的信息使用IOHIDManager获取修改键事件我设法使键盘输入工作,但到目前为止还无法扩展示例代码以生成鼠标事件.代码如下:

 void myHIDCallback(void* context, IOReturn result, void* sender, IOHIDValueRef value)
{
    IOHIDElementRef elem = IOHIDValueGetElement(value);
    if (IOHIDElementGetUsagePage(elem) == 0x07)
    {


        // Keyboard events
        card32 scancode = IOHIDElementGetUsage(elem);
        if (scancode >= 4 && scancode <= 231)
        {
            long pressed = IOHIDValueGetIntegerValue(value);

            KEY_EVENT_DETAILS details = { KEY_EVENT_NONE, NUM_KEYS };

            for (card32 n=0; n<NUM_KEYS; ++n)
            {
                if (n_direct_input_mappings[n].direct_input_key == scancode)
                {
                    details.key_type = n_direct_input_mappings[n].key;
                    break;
                }
            }


            switch (pressed)
            {
                case 0:
                    details.event_type = KEY_EVENT_KEY_DOWN;
                    break;
                case 1:
                    details.event_type …
Run Code Online (Sandbox Code Playgroud)

c++ macos hid

7
推荐指数
0
解决办法
1415
查看次数