KEYBOARD
Test for dead keys
here's what I use in MacSloMo: first, I have a couple of Globals:
DIM KEYuOPTION
DIM KEYuESC
DIM KEYuSPACEBAR
then this function
LOCAL FN dokeys
DIM KeyRec(7)
CALL GETKEYS(KeyRec(0))
IF KeyRec(3) = 4 THEN KEYuOPTION = 1
IF KeyRec(3) = 8192 THEN KEYuESC = 1
KEYuSPACEBAR=FN BITTST(#@KeyRec(3),6) 'SpaceBar
END FN
...that gets called pretty frequently:
ON TIMER(-1) FN dokeys
notice that I used BITTST on KEYuSPACEBAR; this will return 0 when you're not pushing it; KEYuOPTION, however will be 1 until you reset it to 0; this is probably what you want anyway.
No everything is "KeyRec(3)" by the way; it just happened to come out that way.
Here's the program I used to track the KeyRec(x) number = y; just compile and launch when you're in a pinch:
' "how did mel get those numbers?", you ask.
' here's how to get the getkeys numbers for any key...
COMPILE 0,_caseinsensitive
DIM gkeys(7)
END GLOBALS
WINDOW 1,"",(0,0)-(500,300),_dialogshadow
PRINT "press any key to reveal its getkeys numbers..."
DO
CALL GETKEYS(gkeys(0))
' this tells you what the numbers are for each key...
FOR i%=0 TO 7
IF gkeys(i%)<>0 THEN PRINT i%,gkeys(i%),,"click mouse to quit..."
NEXT
' once you know the numbers, here's how you test for them...
LONG IF gkeys(3)=512
COLOR _zblue
PRINT ,,,"that's the spacebar..."
COLOR _zblack
END IF
LONG IF gkeys(3)=-32768 AND gkeys(2)=128
COLOR _zred
PRINT ,,,"that's <command>+<.>"
COLOR _zblack
END IF
UNTIL FN BUTTON
FLUSHEVENTS
On the other hand this works nicely
CLEAR LOCAL
LOCAL FN doMouse
mouseEvent = MOUSE(0)
optionKeyUsed = _false
modifierKeys = EVENT%
IF modifierKeys AND _optionKey% THEN optionKeyUsed = _zTrue
PRINT optionKeyUsed 'just to check it's working
END FN
ON MOUSE FN doMouse
Hope this does it ( and since I'm on the Digest this may be the n-th reply).
Good luck!
I use...
theEvent = {EVENT}
thePoint;4 = EVENT+_evtMouse
modKeys;2 = EVENT+_evtMeta
optDown = modKeys AND _optionKey%
cmdDown = modKeys AND _cmdKey%
ctrlDown = modKeys AND _controlKey%
and it works every time.
|