简体   繁体   English

Macbook OpenEmu Python 发送击键

[英]Macbook OpenEmu Python send keystrokes

I am really impressed by this MarlIO project and want to implement something similar using Python.这个MarlIO 项目给我留下了深刻的印象,并希望使用 Python 实现类似的东西。 However, I got the emulator OpenEmu working, however, I don't know how to control the game using Python.但是,我让模拟器OpenEmu工作,但是,我不知道如何使用 Python 控制游戏。

Isn't it just a matter of sending a few keystrokes?!不就是发送几下按键的问题吗?! Man, it is not that straightforward on a Mac.伙计,这在 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.我想先用COMMAND + TAB切换到openEmu然后打a跳转。 However, when I ran the two commands, it only switched to the OpenEmu, looks like the keystroke a did not got sent.但是,当我运行这两个命令时,它只切换到 OpenEmu,看起来击键a没有被发送。

在此处输入图片说明

However, when I ran 'cmd2' separately, it was clearly working.但是,当我单独运行 'cmd2' 时,它显然工作正常。 Then I testedit against a different application - sublime, and it seemed to work there.然后我针对不同的应用程序进行了测试 - sublime,它似乎在那里工作。

在此处输入图片说明

Can anyone point me to the right direction what I really did wrong with OpenEmu?任何人都可以指出我在 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".我找不到使用 AppleScript 请求持续时间的方法,所以我最终使用Quartz 事件 taps解决了这个问题,例如,“开始按键,睡眠 0.1 秒,停止按键”。 I did it in Swift, but you should be able to do it in Python with the ctype module.我是在 Swift 中完成的,但您应该可以在 Python 中使用ctype模块来完成。

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.向项目维护者提出了这个问题,但由于反应相对冷淡,我拒绝了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM