[futurebasic] Re: [FB] [FB^3] Trapping keystroke events

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 1999 : Group Archive : Group : All Groups

From: Joe Lewis Wilkins <PepeToo@...>
Date: Thu, 25 Nov 1999 19:18:57 -0800
Hi Ken,

I, personally, trap selected Misc. Keys - Option/Command/Function, etc. in a
LOCAL FN that is called from:

ON EVENT      FN doMacEvents 'In the Main Event Loop

This gets everything before FB has a chance to look at it.

Then other keys which allow me to id based on ASCII Numbers in a LOCAL FN that
is called from:

ON EDIT       FN doFilterKeys 'Also in the Main Event Loop, but after ON DIALOG

but I also may call FN doFilterKeys from some doDialog Events now and then

I don't think there is any right or wrong way to do this, though, as always, I
could be wrong. This has worked for me however.

I can pass you some selected FNs privately for doing the above if you'd care to
take a look at them.

Hope the Turkey was good,

Joe Wilkins

Ken Shmidheiser wrote:

> In my quest to better understand trapping keystroke events (outside
> of edit fields) I have developed a little application (it remains
> incomplete) whose code follows. I am asking help with a few questions:
>
> 1). Are there getKey numbers for uppercase keystrokes (as when the
> Shift key is held down to generate an uppercase letter or symbol)? If
> so, how do you trap them?
>
> 2). Ditto for Control/Option/Command keys and their various
> iterations. (I'm sure this has something to do with the <EVENT%
> function> combined with _keyConstant%, but brain drain has fuzzed out
> my synapses).
>
> 3). How do you determine when to use ON DIALOG or ON EVENT to capture
> keystroke event info?
>
> 4). In a totally unrelated matter: In this app I use FN mainRefresh
> to produce the gray window (mimicking Appearance Manager until I can
> figure out how to use it) and CALL RGBBACKCOLOR(#@rgbrecrd) to
> generate the white edit fields. I find it annoying that FN
> mainRefresh overdraws the shadow around the Quit button. Anyone have
> a workaround for this? (I usually use wctb window color resources  to
> color my windows. However, since Appearance Manager was developed,
> Apple has discouraged use of wctbs to avoid future compatibility
> issues.)
>
> This code generates a stand-alone app. Please adjust for e-mail line breaks:
>
> //Keystroke capture application in FB^3 by Ken Shmidheiser 11-99 rev. 3
>
> COMPILE 0,_caseinsensitive
>
> begin globals
> DIM gkeys(7)
> dim gProgramEnds
> DIM rgbrecrd.6
> rgbrecrd.red% = 65535
> rgbrecrd.green% = 65535
> rgbrecrd.blue% = 65535
> end globals
>
> CLEAR LOCAL
> DIM rect;8
> LOCAL FN mainRefresh
> CALL SETRECT(rect, 0, 0, 420, 200)
> PEN  0, 0,1, 8, 0
> LONG COLOR 50935, 50935, 50935
> CALL PAINTRECT(rect)
> PEN  0, 0,1, 8, 0
> LONG COLOR  0, 0, 0
> CALL FRAMERECT(rect)
> CALL PENNORMAL:COLOR=_zBlack
> END FN
>
> Local fn initialize
> WINDOW 1,"",(0,0)-(420,200),_docNoGrow
> FN mainRefresh
> Apple Menu "(This app gets keystroke info...
> Menu 1, 0, _enable, "File"
> Menu 1, 1, _enable, "Quit /Q"
> 'Edit Menu 2
> edit = 4
> CALL RGBBACKCOLOR(#@rgbrecrd)
> Edit Field 1, "Press any key to reveal its getkeys numbers and ASCII
> value..." ,(20,20)-(400,35),_statFramedInvert_hilite
> Edit Field 2, "" ,(20,55)-(400,70),_statFramed
> Edit Field 3, "" ,(20,90)-(400,105),_statFramed
> Edit Field 4, "" ,(20,125)-(330,140),_statFramed
> Edit Field 5, "" ,(20,160)-(330,175),_statFramed
> Button 1, 1, "Quit", (350, 158)-(400, 178), _shadow
> end fn
>
> Local fn getKeys
> CALL GETKEYS(gkeys(0))
> FOR i%=0 TO 7
> long IF gkeys(i%)<>0
> a$ = str$(i%)
> b$ = str$(gkeys(i%))
> c$ = ". Press any key to continue..."
> c$ = "The getKey number is:" + a$ + " " + b$ + c$
> edit$(3) = c$
> xelse
> end if
> NEXT
>
> long if gkeys(3)=512
> edit$(2) = "You've pressed the spacebar..."
> end if
>
> long if gkeys(5)=1024
> edit$(2) = "You've pressed Keypad 0..."
> end if
>
> long if gkeys(5)=2048
> edit$(2) = "You've pressed Keypad 1..."
> end if
>
> long if gkeys(5)=4096
> edit$(2) = "You've pressed Keypad 2..."
> end if
>
> long if gkeys(5)=8192
> edit$(2) = "You've pressed Keypad 3..."
> end if
>
> long if gkeys(5)=16384
> edit$(2) = "You've pressed Keypad 4..."
> end if
>
> long if gkeys(5)=-32768
> edit$(2) = "You've pressed Keypad 5..."
> end if
>
> long if gkeys(5)=1
> edit$(2) = "You've pressed Keypad 6..."
> end if
>
> long if gkeys(5)=2
> edit$(2) = "You've pressed Keypad 7..."
> end if
>
> long if gkeys(5)=8
> edit$(2) = "You've pressed Keypad 8..."
> end if
>
> long if gkeys(5)=16
> edit$(2) = "You've pressed Keypad 9..."
> end if
>
> long if gkeys(4)=-32768
> edit$(2) = "You've pressed Keypad Clear..."
> end if
>
> long if gkeys(5)=512
> edit$(2) = "You've pressed Keypad = ..."
> end if
>
> long if gkeys(4)=8
> edit$(2) = "You've pressed Keypad / ..."
> end if
>
> long if gkeys(4)=2048
> edit$(2) = "You've pressed Keypad * ..."
> end if
>
> long if gkeys(4)=64
> edit$(2) = "You've pressed Keypad - ..."
> end if
>
> long if gkeys(4)=8192
> edit$(2) = "You've pressed Keypad + ..."
> end if
>
> long if gkeys(4)=16
> edit$(2) = "You've pressed Keypad Enter ..."
> end if
>
> long if gkeys(4)=512
> edit$(2) = "You've pressed Keypad . ..."
> end if
>
> long if gkeys(7)=8
> edit$(2) = "You've pressed Arrow key left ..."
> end if
>
> long if gkeys(7)=16
> edit$(2) = "You've pressed Arrow key right ..."
> end if
>
> long if gkeys(7)=64
> edit$(2) = "You've pressed Arrow key up ..."
> end if
>
> long if gkeys(7)=32
> edit$(2) = "You've pressed Arrow key down ..."
> end if
>
> long if gkeys(1)=1024
> edit$(2) = "You've pressed the number 1 ..."
> end if
>
> long if gkeys(1)=2048
> edit$(2) = "You've pressed the number 2 ..."
> end if
>
> long if gkeys(1)=4096
> edit$(2) = "You've pressed the number 3 ..."
> end if
>
> long if gkeys(1)=8192
> edit$(2) = "You've pressed the number 4 ..."
> end if
>
> long if gkeys(1)=-32768
> edit$(2) = "You've pressed the number 5 ..."
> end if
>
> long if gkeys(1)=16384
> edit$(2) = "You've pressed the number 6 ..."
> end if
>
> long if gkeys(1)=4
> edit$(2) = "You've pressed the number 7 ..."
> end if
>
> long if gkeys(1)=16
> edit$(2) = "You've pressed the number 8 ..."
> end if
>
> long if gkeys(1)=2
> edit$(2) = "You've pressed the number 9 ..."
> end if
>
> long if gkeys(1)=32
> edit$(2) = "You've pressed the number 0 ..."
> end if
>
> long if gkeys(0)=256
> edit$(2) = "You've pressed lowercase a ..."
> end if
>
> long if gkeys(0)=8
> edit$(2) = "You've pressed lowercase b ..."
> end if
>
> long if gkeys(0)=1
> edit$(2) = "You've pressed lowercase c ..."
> end if
>
> long if gkeys(0)=1024
> edit$(2) = "You've pressed lowercase d ..."
> end if
>
> long if gkeys(0)=64
> edit$(2) = "You've pressed lowercase e ..."
> end if
>
> long if gkeys(0)=2048
> edit$(2) = "You've pressed lowercase f ..."
> end if
>
> long if gkeys(0)=8192
> edit$(2) = "You've pressed lowercase g ..."
> end if
>
> long if gkeys(0)=4096
> edit$(2) = "You've pressed lowercase h ..."
> end if
>
> long if gkeys(2)=1024
> edit$(2) = "You've pressed lowercase i ..."
> end if
>
> long if gkeys(2)=16384
> edit$(2) = "You've pressed lowercase j ..."
> end if
>
> long if gkeys(2)=1
> edit$(2) = "You've pressed lowercase k ..."
> end if
>
> long if gkeys(2)=8192
> edit$(2) = "You've pressed lowercase l ..."
> end if
>
> long if gkeys(2)=64
> edit$(2) = "You've pressed lowercase m ..."
> end if
>
> long if gkeys(2)=32
> edit$(2) = "You've pressed lowercase n ..."
> end if
>
> long if gkeys(1)=128
> edit$(2) = "You've pressed lowercase o ..."
> end if
>
> long if gkeys(2)=2048
> edit$(2) = "You've pressed lowercase p ..."
> end if
>
> long if gkeys(0)=16
> edit$(2) = "You've pressed lowercase q ..."
> end if
>
> long if gkeys(0)=128
> edit$(2) = "You've pressed lowercase r ..."
> end if
>
> long if gkeys(0)=512
> edit$(2) = "You've pressed lowercase s ..."
> end if
>
> long if gkeys(1)=512
> edit$(2) = "You've pressed lowercase t ..."
> end if
>
> long if gkeys(2)=256
> edit$(2) = "You've pressed lowercase u ..."
> end if
>
> long if gkeys(0)=2
> edit$(2) = "You've pressed lowercase v ..."
> end if
>
> long if gkeys(0)=32
> edit$(2) = "You've pressed lowercase w ..."
> end if
>
> long if gkeys(0)=-32768
> edit$(2) = "You've pressed lowercase x ..."
> end if
>
> long if gkeys(1)=256
> edit$(2) = "You've pressed lowercase y ..."
> end if
>
> long if gkeys(0)=16384
> edit$(2) = "You've pressed lowercase z ..."
> end if
>
> long if gkeys(3)=256
> edit$(2) = "You've pressed Tab ..."
> end if
>
> long if gkeys(3)=1024
> edit$(2) = "You've pressed ` ..."
> end if
>
> long if gkeys(1)=8
> edit$(2) = "You've pressed - ..."
> end if
>
> long if gkeys(1)=1
> edit$(2) = "You've pressed = ..."
> end if
>
> long if gkeys(3)=2048
> edit$(2) = "You've pressed Delete ..."
> end if
>
> long if gkeys(2)=512
> edit$(2) = "You've pressed [ ..."
> end if
>
> long if gkeys(1)=64
> edit$(2) = "You've pressed ] ..."
> end if
>
> long if gkeys(2)=4
> edit$(2) = "You've pressed \ ..."
> end if
>
> long if gkeys(2)=4096
> edit$(2) = "You've pressed Return ..."
> end if
>
> long if gkeys(7)=1024
> edit$(2) = "You've pressed Help ..."
> end if
>
> long if gkeys(7)=2048
> edit$(2) = "You've pressed Home ..."
> end if
>
> long if gkeys(7)=4096
> edit$(2) = "You've pressed Page Up ..."
> end if
>
> long if gkeys(7)=8192
> edit$(2) = "You've pressed Forward Delete ..."
> end if
>
> long if gkeys(7)=-32768
> edit$(2) = "You've pressed End ..."
> end if
>
> long if gkeys(7)=2
> edit$(2) = "You've pressed Page Down ..."
> end if
>
> long if gkeys(3)=8192
> edit$(2) = "You've pressed Escape ..."
> end if
>
> end fn
>
> LOCAL FN doEvent
> evnt& = EVENT
>
> SELECT CASE evnt&.evtNum%
>
> CASE _keyDwnEvt
> char = evnt&.evtMessage& AND &ff
>
> code1$ = "The ASCII code is:"
> ascii$ = str$(char)
>
> code2$ = code1$ + ascii$
> Edit$(4) = code2$
>
> code3$ = "The Hexadecimal code is: "
> hexString$ = HEX$(char)
>
> code4$ = code3$ + hexString$ + " (or, $" + right$(hexString$, 2) + ")"
>
> Edit$(5) = code4$
> code2$ = str$(code%)
>
>   END SELECT
>
> END FN
>
> LOCAL FN doDialog
> dim evnt%
> dim id%
> evnt% = DIALOG(0)
> id% = DIALOG(evnt)
>
> SELECT case evnt%
> case _wndRefresh
> fn mainRefresh
>
> CASE _wndClose
> Edit$(3) = "You've pressed the window close box... bye!
> Delay 800
> gProgramEnds = _true
>
> CASE _btnClick
> SELECT id%
> CASE 1
> Edit$(3) = "You've pressed the Quit button... bye!
> gProgramEnds = _true
> END SELECT
>
> case _evKey
> Edit$(2) = ""
> Edit$(3) = ""
> fn getKeys
>
> END SELECT
> END FN
>
> local fn doMenu
> DIM MenuID%
> dim ItemID%
> MenuID% = MENU(_menuID)
> ItemID% = MENU(_itemID)
>
> select case MenuID%
> case 1
> select case ItemID%
> case 1
> Edit$(3) = "You've selected the Quit menu... bye!
> Delay 800
> gProgramEnds = _true
> end select
> end select
>
> end fn
>
> ON EVENT FN doEvent
> on dialog fn doDialog
> on menu fn doMenu
>
> fn initialize
>
> do
> handleevents
> until gProgramEnds
>
> --
> To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>