10.6.3 os x更新打破了Nestopia的模拟按键 [英] The 10.6.3 os x update broke simulated key-presses for Nestopia

查看:286
本文介绍了10.6.3 os x更新打破了Nestopia的模拟按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布的iPhone应用程序是一个无线游戏控制器,它将设备上的触摸翻译成联网的Mac上的按键。这允许玩使用iPhone作为控制器的模拟器(例如Nestopia)游戏。当然,我发布的这一天恰好与os x更新。安装此更新后,模拟的按键不再在Nestopia中工作!令人吃惊的是,当我在Nestopia中进入文件>打开时,我可以通过点击我的iphone控制器上的向上箭头循环浏览文件列表;即模拟的按键在菜单项中工作,但不在游戏本身中工作。我用来模拟键的代码如下。根据此处的更改列表,任何人都可以识别哪些更改会导致此问题?

The iPhone app that I released is a wireless game controller, it translates touches on the device into key-presses on the networked Mac. This allowed for playing emulator (e.g. Nestopia) games using the iPhone as a controller. Of course, the day that I released it coincided with an os x update. After installing this update, the simulated key-presses no longer work in Nestopia! The crazier thing is, when I go to 'File > Open' within Nestopia, I can cycle through the file list by hitting the up-arrow on my iphone controller; i.e. the simulated key-presses work in menu items, but not in the game itself. The code that I use to simulate keys is below. Given the list of changes here, can anyone identify which change would cause this problem?

谢谢!

#define UP  false
#define DOWN true

-(void)sendKey:(CGKeyCode)keycode andKeyDirection:(BOOL)keydirection{
  CGEventRef eventRef = CGEventCreateKeyboardEvent(NULL, keycode, keydirection);
  CGEventPost(kCGSessionEventTap, eventRef);
  CFRelease(eventRef);
}


推荐答案

Mac Nestopia的作者使用较早的调用GetKeys()来捕获关键事件。从10.6.3,GetKeys不捕获生成的按键使用本文中详述的方法。我发现的解决方法是改用:

The author of Mac Nestopia is using an older call, GetKeys(), to capture key events. As of 10.6.3, GetKeys does not catch generated key presses using the methods detailed in this post. The workaround I found was to use this instead:

-(void)sendKey:(CGKeyCode)keycode andKeyDirection:(BOOL)keydirection{
  AXUIElementRef axSystemWideElement = AXUIElementCreateSystemWide();
  AXError err = AXUIElementPostKeyboardEvent(axSystemWideElement, 0, keycode, keydirection);
  if (err != kAXErrorSuccess)
    NSLog(@" Did not post key press!");
}

非常感谢Richard Bannister的快速电子邮件回应!

Huge thanks to Richard Bannister for his quick email responses!

这篇关于10.6.3 os x更新打破了Nestopia的模拟按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆