A question about repeatable keystrokes?

FIrst off I am sorry if this has been answered before, I tried to search but I don’t even know what I am really looking for. I am very new to OSX, literally have been using my new mac for about 6 hours :slight_smile:

I am looking for a script that will spam a keystroke about 100 times a minute or so, I tried modifying a autohotkey macro but applescript is without a doubt foreign to me.

tell application "System Events"
	tell application "World of Warcraft" to activate
	keystroke "1"
end tell

This is sorta what I have been working with, understand that the “1” key would be bound for to a macro and spamming would be nessessary use the macro and I would simply like to hold down 1 and applescript to repeat the keystroke.

Thanks in advance.

tell application "System Events"
   tell application "World of Warcraft" to activate
repeat
   keystroke "1"
end repeat
end tell

is that what you mean?

EDIT:: Okay I just tried it, and the big problem is that the repeatable “1” is always on, is there anyway to trigger the spam with say a hold of “1”. The big thing is that you need to do other things then just spam 1 all the time so if you can toggle it on and off with a keystroke that would be great.

This is Leopard only.
This script uses the CAPS Lock key (on actual keyboard) as the toggle. CAPS Lock key depressed, keystrokes the 1’s, CAPS Lock key released it stops.
( I assume you will amend the script to a stay open type app.)

I do not have “World of Warcraft” so I tested with “TextEdit”
The Keyboard Viewer does not need to be visable. So if it pops up the first time you run it just close it

tell application "System Events"
	tell application "KeyboardViewerServer" to activate
	set CAPS to (get value of checkbox "⇪" of window 1 of application process "KeyboardViewerServer") as number
	if CAPS is 1 then
		tell application  "World of Warcraft" to activate
		repeat until CAPS is 0
			set CAPS to (get value of checkbox "⇪" of window 1 of application process "KeyboardViewerServer") as number
			keystroke "1"
		end repeat
	end if
end tell

wow, this is pretty clever, Mark :slight_smile:

Thanks Stefan, :smiley:

It took me a while to work out a way to detect Caps lock, finally had that eureka moment about a week ago, when trying to help out on a script post 75, Mainthread

Heres the stay open app form (save as as stay open application)

on idle
	tell application "System Events"
		tell application "KeyboardViewerServer" to activate
		set CAPS to (get value of checkbox "⇪" of window 1 of application process "KeyboardViewerServer") as number
		if CAPS is 1 then
			tell application  "World of Warcraft" to activate
			repeat until CAPS is 0
				set CAPS to (get value of checkbox "⇪" of window 1 of application process "KeyboardViewerServer") as number
				keystroke "1"
			end repeat
		end if
		return 1
	end tell
end idle

WoW that is pretty incredible stuff. Thanks alot it works great.

Wow really cool Script i’ve been looking for something like this for hours…
As applescript-newbie i have problems modifying this script.
Is it possible to use the left ctrl key to activate the script instead of caps?

ctrl key is not an ideal key to use, but it works
I only have one ctrl key on my laptop, which lists as checkbox 63
The “⌃” works also, but if you have two ctrl keys you will need to find its checkbox number

on idle
	tell application "System Events"
		tell application "KeyboardViewerServer" to activate
		set CTRL to (get value of checkbox 63 of window 1 of application process "KeyboardViewerServer") as number
		if CTRL is 1 then
			tell application "TextEdit" to activate
			repeat until CTRL is 0
				set CTRL to (get value of checkbox 63 of window 1 of application process "KeyboardViewerServer") as number
				keystroke "1"
			end repeat
		end if
		return 1
	end tell
end idle

First of all, thanks for your help, but how can i determine the checkbox number of the keys?

Hi,

I postet this before, unfortunately the post did not work.

So my problem ist: I used the script above, but when it runs it says:

Die Datei žKeyboardViewerServer" wurde nicht gefunden.
This means that the file žKeyboardViewerServer" was not found.

Can anybody help me solving this problem?
Thanks!

Hi,

in the Finder press ⇧⌘G , paste this path
/System/Library/Components/KeyboardViewer.component/Contents/SharedSupport/
and press return.

If there is no KeyboardViewerServer.app, it’s obviously not installed.
If the app exists, start it once. After that the application should react to the application tell block

Thanks for your answer.
I tested it, and the app is there: KeyboardViewerServer.app

But when I try to run ist - nothing happens?
Also I cant find a process running in the activity monitor.

Therefore I stil get the same error message.

hm, strange.
KeyboardViewerServer.app is responsible for the keyboard viewer panel, which can be accessed from the Input Menu
Here is a screenshot

Ok, I tried something else:
Went to System/Library/Caches und trashed the follwing files:

com.apple.IntlDataCache.le
com.apple.IntlDataCache.le.kbdx
com.apple.IntlDataCache.le.sbdl
com.apple.IntlDataCache.le.tecx

Then restartet und went to the international preference pane
There I activated the keyboard viewer panel, and it came up as you said (the same app as on your screenshot).
When I run the script now I get the following error:

žSystem Events" hat einen Fehler erhalten: žwindow 1 of application process “KeyboardViewerServer”" kann nicht gelesen werden. Ungültiger Index.
This Means: Window 1 can not be read.