I am having trouble figuring out how to detect a key being pressed in AppleScript and how to delay until that key is released. I want to make a toggle for zoom, and I have everything else (I think). This is my current code
on idle
set ztoggle to 0
repeat
--how do i make it so a key is needed to run this loop? maybe an 'if (im not sure what to put here) then' loop?--
if (ztoggle = 1) then
set ztoggle to 0
else if (ztoggle = 0) then
set ztoggle to 1
end if
--how do i make it so the program waits at this line until the key from before is released? i was thinking delay, but im not sure--
if (ztoggle = 1) then
tell application "System Events"
key code 28 using {option down, command down}
end tell
end if
set ztoggle to 0
end repeat
end idle
Does anyone know how I would do this? Also, this is my first time trying anything with AppleScript, so if I messed up elsewhere, let me know.