Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript Keystroke not working

I have an application (Elite Dangerous for Mac) and I am trying to send key strokes to it using AppleScript. It is not a "scriptable" application officially, but it seems to me that it should still respond to a "keystroke" or "key code" command from an AppleScript should it not??


Don't the "keystroke" or "key code" commands using "System Events" mimic an actual keyboard? Could an application know the difference between me using an actual, physical keyboard or sending "keys" from AppleScript??


Are there any alternative methods for accomplishing this in AppleScript?

Posted on Jun 2, 2015 6:38 PM

Reply
7 replies

Jul 31, 2017 10:09 AM in response to klandry

Hi there Klandry, CMDR Ame coming at you. I've been experimenting with this and I've found that in the applescript you have to send the keystroke as if the command key was down for some reason. For example, to deploy hardpoints, if bound to the "u" key, the applescript would be:

activateapplication "EliteDangerous"

delay 0.25

tell application "System Events" to keystroke "u" usingcommand down


The 0.25 second delay has to be in there to make ED realize that we're not hacking the game somehow by having the computer spam a key instantaneously. Works for me in windowed mode for ED, not sure about fullscreen.


Hope this helps!

Sep 1, 2017 6:53 PM in response to Alessandro_M

I have been experimenting with this as well in an effort towards a communications gateway. For example, this script sends the current local time to in game comms. My eventual goal is to have it interact with the game logfile and IRC to accomplish something clever.


activate application "EliteDangerous"

tell application "System Events"

repeat 2 times

delay 0.3

keystroke "c" using command down

end repeat

delay 0.3

keystroke time string of (current date)

delay 0.3

key code 36 using command down

end tell

Jun 4, 2015 10:31 AM in response to rccharles

Sorry, I should have stated that I have tested it with numerous other applications and it works as expected with all of them.


The only difference is that this application is built on the MonoGame Framework (which allows it to be cross-platform), although I don't see why that should make any difference if the AppleScript key functions are sending keystrokes through the same keyboard buffer as the physical keyboard.

Jun 4, 2015 11:08 AM in response to klandry

Some games have software programming to filter out keystrokes generated by automated programs. Games check the speed of keystroke arrival -- typed too fast for a human, the time between keystrokes -- too little time between keystrokes, and you can guess what else.


I suggest you write a function the takes input of a string and sends it out in a random fashion.

Jun 4, 2015 12:15 PM in response to rccharles

I am only sending one keystroke at a time (one letter in most cases). I had also tried using the AppleScript keydown and keyup functions with varying delays between them. No luck.


I even talked with a developer from the company that makes the game and he wasn't sure why AppleScript key functions wouldn't work either but he was aware of the fact that AppleScript doesn't seem to work.

Jun 4, 2015 2:37 PM in response to klandry

Mystery. At one time and I assume there still is some full screen game interface. Must be using a different interface to the keyboard.


Maybe a different type of keylogger would work.

http://plumamazing.com/mac/ikey/userraves

be sure to try before buying. not sure if ikey is such any more.


Try posting your question here.

http://community.monogame.net/


Robert

AppleScript Keystroke not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.