Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Yodan1

macrumors newbie
Original poster
Nov 24, 2006
4
0
Please, I have been looking for this action in Applescript for about a week now on dozens of websites, with no success. All I am looking for is a simple action that holds down a button, the X key in this case, for a specified number of seconds. Thats all. I can't find this anywhere on any resource or forum post. Does anyone have a clue? Why is it so hard to find an action for "Press this key and hold it for 10 seconds"? :confused:
 

Yodan1

macrumors newbie
Original poster
Nov 24, 2006
4
0
Well, I've been playing the game Tremulous for a while, and just started using Speakable Items for my Mac. I've been making macros, like Reload to well...reload, and so on. Just so happens that holding X makes you run. It's been crazing my mind for a while and I can't find the answer anywhere. WASD while holding X is such a hassle. I wanted to have the script hold down X for 10 seconds when I say Run. That way, no need to hold down the awkward keys.
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
Too lazy to break out my AppleScript book right now, but I believe there are commands like key down and key up that allow you to "press" a key down, then release it later instead of giving a single keypress.

EDIT: A quick test using Script Editor and the Keyboard Viewer seems to indicate that the following will work for you (replace 10 with the length of time in seconds that you need the key held down for):

Code:
tell application "System Events"
	key down "v"
	delay 10
	key up "v"
end tell

Keys pressed down this way don't seem to autorepeat (ie you only get one "v" in TextEdit, not a bunch) but Keyboard Viewer does show that the key is pressed down for the full duration of the delay. If you need a repeated keystroke, the code that Unorthodox posted is probably better.
 

Unorthodox

macrumors 65816
Mar 3, 2006
1,087
1
Not at the beach...
Too lazy to break out my AppleScript book right now, but I believe there are commands like key down and key up that allow you to "press" a key down, then release it later instead of giving a single keypress.

EDIT: A quick test using Script Editor and the Keyboard Viewer seems to indicate that the following will work for you (replace 10 with the length of time in seconds that you need the key held down for):

Code:
tell application "System Events"
	key down "v"
	delay 10
	key up "v"
end tell

Keys pressed down this way don't seem to autorepeat (ie you only get one "v" in TextEdit, not a bunch) but Keyboard Viewer does show that the key is pressed down for the full duration of the delay. If you need a repeated keystroke, the code that Unorthodox posted is probably better.
I tested that in another game where you hold down a button to sprint and it works perfectly.
What I suggested doesn't work and prevents you from moving. :eek: :p
 

Yodan1

macrumors newbie
Original poster
Nov 24, 2006
4
0
If I had arms over the internet, i would hug you. Thanks so much. You have no idea how busy I've been trying to think in simple English for easy commands in applescript. Down and up seem simple enough. Thank you all!:)
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
If I had arms over the internet, i would hug you. Thanks so much. You have no idea how busy I've been trying to think in simple English for easy commands in applescript. Down and up seem simple enough. Thank you all!:)

No problem, glad I could help. That's kind of the thing about AppleScript. It's really easy to read even if you don't have any experience with it, but the same is not really true of writing it. It seems like you can never figure out which plain English phrase to use to get it to work. If you are interested in learning more AppleScript stuff, check out AppleScript: The Missing Manual. It's a pretty good book and while it won't make you an expert, it'll get you to where you can at least feel comfortable enough to search through things on the web and in the documentation to figure how to do what you want to do.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.