omron — Detecting User Input

Detecting User Input Keyboard Mode The default mode is Keyboard. If a PENDANT( ) function requests any keyboard input, the key number of the first Keyboard mode key pressed is returned. The following code detects the first function key pressed: ; Set the function keys to keyboard mode KEYMODE 1,4 = 0 ; Wait for a key press from keys 1 - 4 DO key = PENDANT(0) UNTIL key 5 The arguments to the KEYMODE instruction indicate that pendant keys 1 through 4 are to be configured in Keyboard mode. The 0 argument to the PENDANT( ) function indicates that the key number of the first key pressed is to be returned.

Toggle Mode To detect the state of a key in Toggle mode, the PENDANT( ) function must specify the key to be monitored. When a key is configured as a toggle key, its state is maintained as ON (-1) or OFF (0). The state is toggled each time the key is pressed. The following code sets the F1 key to Toggle mode and waits until F1 is pressed: ; Set the F1 key to toggle KEYMODE 1 = 1 ; Wait until the F1 key is pressed WHILE NOT PENDANT(1) DO RELEASE -1 END Level Mode To detect the state of a key in Level mode, the PENDANT( ) function must specify the key to be monitored. When a key has been configured as a level key, the state of the key is ON as long as the key is pressed.

When the key is not pressed, its state is OFF. The following code will poll the OK button's state until it has been held down for an amount of time. If it is released prematurely, the counter is reset. ATTACH(1) "PENDANT" counter = 0 KEYMODE 18, 18 = 2 WHILE counter 20 DO IF PENDANT(18) THEN counter = counter+1 ELSE counter = 0 END eV+Language User's Guide, v2.x, 18318-000 Rev A Page 182