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