![]() |
Hey anyone know how to simulate keys to an app?!
I have an app that requires a key press every 2 minute. Anyone know of a way to simulatte key press to an app without focus? In windows I used to use autoit a script language to send keys to apps. Anything like that mac?
|
Yes, Applescript is built in. There are some examples on the following page that shows how to simulate a key press with Applescript:
http://dougscripts.com/itunes/itinfo/keycodes.php Trevor |
thank you for your help but the problem is that method only worksfoe the frontmost application
|
There are various third-party utilities that provide "hot keys" or "key macros" - search on www.update.com
|
I'm not sure those hot keys programs does what I want, I think they watch your key presses and perform some actions? It doesnt actually send keys?
|
Quote:
|
What is the code for applescript to send to any open application?
|
You need to specify which app you want to send the command to by starting with something like:
tell application "Safari" |
what is the next line?
|
Quote:
|
No, try that, it doesnt work, those lines only work for frontmost applications, read that page
Quote:
|
The "activate" in the example scripts makes the app come to the foreground. You could put it back in the background afterwards.
Maybe you want to back up a bit and tell us why you need to send key presses to an app that is in the background - maybe we can help solve your higher-level problem. |
Hayne, its an old app that requires me to press space every 2 min or so before it can continue. All I want to do is send a key, its not complicated. I dont want it to ever come to the foreground because I want to continue to use my computer with it doing its thing in the background.
|
Quote:
|
Its an app that my company wrote, small. I wish someone could tell me how to send keys :(
|
Quote:
|
so source code is provided. This cant be true, OSX CANNOT send keys to unfocused applications????
|
Hayne already explained that it can.
Post #4 in this thread includes an applescript by son_t that presses the keys that invert the screen, for example. Trevor |
Thanks but, so I tried that script and tried to change it to an targeted application and then it will give me an script error, saying syntax error
tell application "TextEdit" tell application processes key code 28 using {command down, option down, control down} end tell end tell |
I think the first two lines need to be instead:
Code:
tell application "System Events" |
Try this
tell application "System Events" tell application process "TextEdit" key code 28 end tell end tell Does not send a key to textedit |
| All times are GMT -5. The time now is 10:33 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.