Emulate keypress

Is this possible? I am working with a programm which controls electric motors for moving scenary, it runs on apple, the program requires that control and alt are pressed together before it will allow you to move a motor, a dead mans handle. There is a xmas show which will require a motor to be running all day everyday and I want to bypass the dead mans handle.
Would it be possible to write an applescript to fool the computer into thinking that the control and alt keys were constantly being pressed?

TIA

G5

Posted on Oct 4, 2010 10:04 AM

Reply
6 replies

Oct 4, 2010 10:49 AM in response to Paddyconachair

Tape the keys down?

-----

(*
Remember you need to enable assistive devices.
This lets applications software access screen elements.

blue apple > system perferences > universal access > enable assistive devices
*)

-- Write a message into the event log.
(*
Run this program from the Script Editor. Click on the Event Log tab at the
bottom of the screen.
*)
log " --- Starting on " & ((current date) as string) & " --- "


set the_item_ref to choose file with prompt "Select an html, text, or some other file Safari will display."

-- Activate
activate application "Safari"

-- Open the URL
tell application "Safari"
open the_item_ref

-- print
-- System Events interacts with the current active applications.
tell application "System Events"
tell process "Safari"
-- Your simulating typing on the keyboard. You need to allow time
-- for the application to run. It's always a guess about delay in seconds.
delay 3

-- Be sure your printer is up & running before printing.
keystroke "p" using command down
delay 3
keystroke return
delay 10
keystroke "w" using command down

end tell
end tell

end tell -- of Safari




-----------

iKey is a front end program that simulates typing and mouse movements. I use iKey to remap the Function keys.

"iKey is an automation utility, a program that creates shortcuts to accomplish repetitive tasks. In essence, an iKey shortcut is a little program in its own right, but you don't need to know the first thing about programming to create an iKey shortcut. All you have to do is put together three necessary parts of a shortcut: One or more commands that give the shortcut its functionality, a context in which it runs, and a launcher that defines how the shortcut is activated."
http://www.scriptsoftware.com/ikey/



iKey has a little more function then the previous free version called youpi key. For many years, I used youpi key before switching to iKey. It works fairly well for me in MAC OS 10.4 although not officially supported. The youpi key download is hard to find & no longer here.
http://www.versiontracker.com/dyn/moreinfo/macosx/11485&vid=75326


Examples:

  1. I have the common programs that I use assigned to function keys. I have F4 assigned to Firefox. When I want to start FireFox, I press F4. When I want to switch to firefox, I press F4! Starting & switching to an application in Mac OS are the same thing in Mac OS.

  2. Here is an example of to assign volumn control to a function key.
    http://discussions.apple.com/message.jspa?messageID=10361085#10361085

  3. Here is my script for listing my application folder. I have it assigned to function-key 6.
    !http://farm3.static.flickr.com/2689/4292832695_f3a8f1122e.jpg!
    tell application "Finder"
    open folder "Applications" of startup disk
    select Finder window 1
    set bounds of Finder window 1 to {-3, 44, 691, 545}

    --set position of Finder window 1 to {33, 44}
    set position of Finder window 1 to {60, 45}
    activate
    end tell

    The second portion of this script was generated in the script editor record mode. After I recorded the script and did some editing, I copy the script to ikey/youpi key.


Robert

Oct 4, 2010 12:34 PM in response to Paddyconachair

Are you running anything else on the Mac while this program is running?
If so, then _do not_ do this.
Otherwise, adjust delay to suit your needs:


<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #E6E6EE;
overflow: auto;">
tell application "System Events"
key down {control, option}
delay 5
key up {control, option}
end tell</pre>

Oct 5, 2010 1:14 AM in response to Tony T1

Tony T1 wrote:
Are you running anything else on the Mac while this program is running?
If so, then _do not_ do this.
Otherwise, adjust delay to suit your needs:


<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
font-weight: normal;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #E6E6EE;
overflow: auto;">
tell application "System Events"
key down {control, option}
delay 5
key up {control, option}
end tell</pre>




Nothing else that I know of, the program uses tcp/ip to talk to the motors. Why the warning about other programs? Thanks though.

Oct 5, 2010 10:19 AM in response to Tony T1

Every program will think that {option, command} is being pressed.


My understanding is the system events for key presses only interacts with the active process.

These commands are simulating the keyboard so they should act like you pressing the keys on the keyboard.

Of course, if the active process should change, you would be sending these keys to that process.

-------

I there some documentation on System Events? Reading the dictionary doesn't do it for me.

Robert

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Emulate keypress

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