KEYPRESSED ( n )
Purpose Return the keycode of the key being pressed on the keypad.
Parameters
n = 0 :Unfiltered - Return keycode of currently-pressed key
n = 1 : Filtered - Return keycode only once when a key is pressed. Returns -1 on subsequent reads even if the key is pressed and hold and not released. Return correct keycode again if the key is released and then pressed again. This is most useful for TBASIC programming to prevent rapid repeat entry.
n = 2 :Bit-set - Return a 16-bit word whose bit position is set corresponds to the keycode value. E.g. if keycode = 5, KEYPRESSED(2) returns a word whose bit #5 is set. i.e &H0020 (binary 0000 0000 0010 0000). This is useful if you want to map the key pressed to relay contacts for ladder logic processing. E.g RELAY[3] = KEYPRESSED(2)
Examples A = KEYPRESSED ( 1 )
Comments:
The keypad on Wx PLC has 16 keys and this function returns value between 0 and 15. Key 0..9 on the standard Wx PLC keypad would return keycode from 0 to 9. The keycode of the other keys are shown on the virtual HMI keypad on the "View Variable" screen as shown above. E.g. pressing the "Enter" key will return a keycode of 11, and pressing the backspace key will return keycode of 15. This function returns -1 when no key has been pressed.

Note that the actual value returned by KEYPRESSED ( n ) depends on the parameter n as described in the "Parameters" section.

For a complete example please download the sample program: KeyPressed_Demo.PC7


backbutton.gif (507 bytes)  Basic to TBASIC Reference Manual