简体   繁体   中英

Macbook OpenEmu Python send keystrokes

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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