Difference between revisions of "ON KEY(n)"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 6: Line 6:
  
  
''Description:''
+
* Predefined and user defined KEY event number assignments to use with ON KEY(n):
* Predefined key numbers are shown below, where n is the number that represents that key.
+
{{WhiteStart}}    '''1 to 10'''.............Reserved '''F1 to F10''' function keys only.
:'''1 - 10''' for '''F1 - F10''' function keys respectively
+
    '''11, 12, 13 and 14'''...Reserved '''Up, Left, Right and Down''' numeric keypad arrows only
:'''11, 12, 13 and 14''' for '''UP, LEFT, RIGHT and DOWN''' numberpad arrows respectively.
+
    '''15 to 29'''............'''user-defined keys''' using value: [[CHR$]](keyflag)  + [[CHR$]]([[Keyboard scancodes|scancode]])
:'''15-25(29 in QB64)''' for '''user-defined keys'''. See: [[KEY n]], [[Keyboard scancodes]]
+
    '''30 and 31'''...........Reserved '''F11 and F12''' function keys only.
:'''30 - 31''' for '''F11 - F12''' function keys
+
{{WhiteEnd}}
 +
* See the [[KEY n]] page for user defined key or key combination presses and F function softkey assignments.
 
* [[GOSUB]] with a ''linelabel'' or ''linenumber''  or a [[SUB]] procedure can be used in '''QB64'''. Don't use [[CALL]]!
 
* [[GOSUB]] with a ''linelabel'' or ''linenumber''  or a [[SUB]] procedure can be used in '''QB64'''. Don't use [[CALL]]!
 +
  
  

Revision as of 16:34, 4 May 2012

The ON KEY(n) statement defines a line number or label to go to when a specified key is pressed. QB64 can reference a SUB.


Syntax

ON KEY (n) {GOSUB {linelabel|linenumber}|SUBprocedure}


  • Predefined and user defined KEY event number assignments to use with ON KEY(n):

1 to 10.............Reserved F1 to F10 function keys only. 11, 12, 13 and 14...Reserved Up, Left, Right and Down numeric keypad arrows only 15 to 29............user-defined keys using value: CHR$(keyflag) + CHR$(scancode) 30 and 31...........Reserved F11 and F12 function keys only.

  • See the KEY n page for user defined key or key combination presses and F function softkey assignments.
  • GOSUB with a linelabel or linenumber or a SUB procedure can be used in QB64. Don't use CALL!


Example 1: Using ON KEY with GOSUB to execute code.

KEY(1) ON ON KEY(1) GOSUB trap PRINT "Press F1 to quit!" DO:LOOP 'never ending loop trap: PRINT "You pressed F1 like I told you to :)" END RETURN


Example 2: Setting multiple ON KEY statements to send different values to a SUB procedure.

FOR n = 1 TO 10 KEY n, STR$(n) ' assigns soft key as a numerical string ON KEY(n) Funct n 'designate SUB procedure and parameter value passed KEY(n) ON ' turns each key event monitor on NEXT KEY ON 'displays F1 to F10 soft key assignments at bottom of screen DO LOOP UNTIL INKEY$ = CHR$(27) END SUB Funct (num%) CLS' clears the screen and refreshes bottom soft key list PRINT "You pressed F"; LTRIM$(STR$(num%)) END SUB


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page