Name:
keyin
Syntax:

KEYIN

Description:

This command is deprecated, please consider using the kbin command instead.

Wait until a new keyboard press is received.

This command is used to wait for a new key press from a computer keyboard (connected directly to the PICAXE - not the keyboard used whilst programming, see the keyled command in section 2 of the manual for connection details). All processing stops until the new key press is received.

The value of the key press received is placed in the predefined variable 'keyvalue'. Note the design of the keyboard means that the value of each key is not logical, each key value must be identified from the table listed in manual 2. Some keys use two numbers, the first $E0 is ignored by the PICAXE and so keyvalue will return the second number. Note all the codes are in hex and so should be prefixed with $ whilst programming. The PAUSE and PRNT SCRN keys cannot be used reliably as they have a special long multi-digit code. Also note that some keys may not work correctly when the 'Nums Lock' LED is set on with the keyled command. The sample file 'keyin.bas' (installed in the \samples folder) provides details on how you can convert the key presses into ASCII characters by means of a look up table.

After using this command you may have to perform a hard reset to download a new program to the microcontroller.

Effect of Increased Clock Speed

This command will only function at 4MHz.

Applies To:
18A, 18M, 18X, 28X, 40X
See Also:
Related Create:
Share:
Print:

Keyboard toggling a LED

When a key is pressed which has keycode value $25 a LED on output B.1 is turned on, and turned off when a key is pressed which has keycode value $45.

Code Example:
main:	keyin				; wait for new signal
	if keyvalue = $25 then swoff1	; switch off 1
	if keyvalue = $45 then swon1	; switch on 1
	goto main

swon1:	high 1
	goto main
swoff1:	low 1
	goto main
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.