Macbook OpenEmu Python发送击键 [英] Macbook OpenEmu Python send keystrokes
问题描述
但是,当我分别运行"cmd2"时,它显然可以正常工作.然后我针对另一个应用程序进行了测试-崇高,它似乎在那里工作.
有人能指出我正确的方向吗?我对OpenEmu的真正错误是什么?
几个月前,我做了类似的事情.击键被发送.但是,系统事件键击几乎不会持续任何时间,因此模拟器的输入机制不会将它们拾取.
我找不到要求使用AppleScript的时间的方法,因此我最终使用石英事件点击,例如,您可以执行开始按下键,睡眠0.1秒,停止按下键".我是在Swift中完成的,但是您应该可以在Python中使用 ctype
模块来实现它.
还请注意,可能难以在帧上与仿真器进行同步.我提出了项目维护者的问题,但由于反应相对冷淡,我拒绝了
I am really impressed by this MarlIO project and want to implement something similar using Python. However, I got the emulator OpenEmu working, however, I don't know how to control the game using Python.
Isn't it just a matter of sending a few keystrokes?! Man, it is not that straightforward on a Mac.
In [41]: cmd1
Out[41]: '\nosascript -e \'tell application "System Events" to key code 48 using {command down}\' \n'
In [42]: cmd2
Out[42]: '\nosascript -e \'tell application "System Events" to keystroke "a"\' \n'
I want to first use COMMAND+TAB to switch to the openEmu and then hit a to jump. However, when I ran the two commands, it only switched to the OpenEmu, looks like the keystroke a did not got sent.
However, when I ran 'cmd2' separately, it was clearly working. Then I testedit against a different application - sublime, and it seemed to work there.
Can anyone point me to the right direction what I really did wrong with OpenEmu?
I did something like that a few months ago. The keystrokes are sent. However, System Event keystrokes last virtually no time, so the emulator's input mechanism doesn't pick them up.
I couldn't find a way to ask for a duration with AppleScript, so I ended up solving the problem using Quartz event taps, which let you do, for instance, "start pressing key, sleep 0.1s, stop pressing key". I did it in Swift, but you should be able to do it in Python with the ctype
module.
Also note that it might be difficult to synchronize on a frame basis with the emulator. I raised that problem with the project maintainers, but I turned away because of the relatively cold response.
这篇关于Macbook OpenEmu Python发送击键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!