- This wiki is out of date, use the continuation of this wiki instead
Key
From FenixWiki
(Difference between revisions)
Revision as of 21:23, 25 June 2007 (edit) 87.177.23.239 (Talk) ← Previous diff |
Revision as of 21:23, 25 June 2007 (edit) (undo) 87.177.23.239 (Talk) Next diff → |
||
Line 2: | Line 2: | ||
=== Definition === | === Definition === | ||
---- | ---- | ||
- | '''key()''' is a [[function]] that needs a [[constant]] or a [[variable]] with the scancode | + | '''key();''' is a [[function]] that needs a [[constant]] or a [[variable]] with the scancode |
or the scancode itself for the key you want to check. | or the scancode itself for the key you want to check. | ||
The [[variable]] [[ascii]] shows the scancode of the key currently pressed. | The [[variable]] [[ascii]] shows the scancode of the key currently pressed. | ||
Line 8: | Line 8: | ||
The [[constant]]s for the keys commonly start with _ + the key. | The [[constant]]s for the keys commonly start with _ + the key. | ||
- | So if you want to check for the letter 'a' to be pressed, you would pass _a to key(). | + | So if you want to check for the letter 'a' to be pressed, you would pass _a to '''key();'''. |
- | You can find a list of the | + | You can find a list of the [[constant]]s and scancodes here. |
=== Example === | === Example === |
Revision as of 21:23, 25 June 2007
Definition
key(); is a function that needs a constant or a variable with the scancode or the scancode itself for the key you want to check. The variable ascii shows the scancode of the key currently pressed. This function returns 0 or false if the key is not pressed, 1 or true if it is pressed.
The constants for the keys commonly start with _ + the key. So if you want to check for the letter 'a' to be pressed, you would pass _a to key();.
You can find a list of the constants and scancodes here.
Example
program input_test; begin set_mode(320,240,16); set_fps(60,0); while( !key(_esc) ) delete_text(); if( key(_left) && !key(_right) ) write(0,160,120,4, "LEFT"); end; if( key(_right) && !key(_left) ) write(0,160,120,4, "RIGHT"); end; frame; end; exit(); end;
This will output the words LEFT or RIGHT according to the keys you press, or it will quit the program once ESCAPE is pressed.