keystroke

141 views
Skip to first unread message

Kalman Tarr

unread,
Jul 6, 2022, 3:51:55 AM7/6/22
to QLab
Hi everyone,

I need to read or get Mac keystroke in a script I using.
I mean:
(it is just a silly example)
tell .........
if keystroke is "1" then
--do something
else if keystroke is "2" then
--do another thing
else if keystroke is "3" then
--do else
end if
end tell

Any suggestion?

Best,

Kalman

micpool

unread,
Jul 6, 2022, 4:18:41 AM7/6/22
to QLab
Not easily. Applescript does not have the ability to interact with keyboards in this way.

QLab can use keyboard triggers to fire cues, so you can have a separate  script on each key. 

If you need keyboard input within a script   These scripts could set a parameter in a dummy cue which your main script could read


Mic

Kalman Tarr

unread,
Jul 6, 2022, 6:45:46 AM7/6/22
to ql...@googlegroups.com
Copy
THX Mic

--
Contact support anytime: sup...@figure53.com
Follow QLab on Twitter: https://twitter.com/QLabApp
User Group Code of Conduct: https://qlab.app/code-of-conduct/
---
You received this message because you are subscribed to the Google Groups "QLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qlab+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qlab/2dd8e9a0-53c7-40ad-8968-19e4843043e0n%40googlegroups.com.

micpool

unread,
Jul 6, 2022, 2:14:17 PM7/6/22
to QLab
Here's how to do it. (It's not completely straightforward because you have to make Applescript run 2 processes asynchronously.)

To do this you put the dialog up outside of QLab's processes after starting a script cue that does the keypress processing inside QLab's processes.

The responses are stored in the post wait of a dummy disarmed cue "VAR" and are set by 4 network  cues, triggered by keys 1-4,  with OSC messages that set the post wait of cue "VAR" to 1,2,3 or 4
when you run cue "D" this script is run:


tell application id "com.figure53.QLab.4" to tell front workspace to start cue "A"
display dialog " Which option would you like" & return & " Press 1 for option 1" & return & " Press 2 for option 2" & return & " Press 3 for option 3" & return & " Press 4 to cancel" buttons "Use Keyboard for Entry"

The asynchronous response script is in cue "A"

--asynchronous applescript to be started by  cue "D"
delay 0.4
tell application id "com.figure53.QLab.4" to tell front workspace
    --take focus back from dialog window
    activate
    --reset response to null (responses are stored in post wait of cue "VAR")
    set the post wait of cue "VAR" to 0
    -- repeat until there is a valid response        
    repeat
        --If dialog has been dismissed in dialog window  with mouse then stop everything
        if running of cue "D" is false then return
        --exit if  valid key is pressed
       
        if (post wait of cue "VAR" as integer) is greater than 0 and (post wait of cue "VAR" as integer) is less than 5 then
            set theOption to post wait of cue "VAR"
            exit repeat
        end if
    end repeat
    --dismiss dialog
    stop cue "D"
    --do something depending on option selected
    if theOption = 1 then
        say "You selected Option 1"
    else if theOption = 2 then
        say "You selected Option 2"
    else if theOption = 3 then
        say "You selected Option 3"
    else
        --cancel if keypress was 4
        return
    end if
   
end tell

micpool

unread,
Jul 6, 2022, 2:16:54 PM7/6/22
to QLab
Here's the workspace

Screenshot 2022-07-06 at 19.15.58.png
Workspace attached

Mic
Keyboard response.qlab4

Kalman Tarr

unread,
Jul 8, 2022, 9:57:20 AM7/8/22
to QLab
Thanks Mic,
your answer is beyond my expectation.
I am going to  try your offer shortly.
Best

Kalman

Reply all
Reply to author
Forward
0 new messages