This repository has been archived by the owner on May 21, 2024. It is now read-only.
forked from boriel-basic/zxbasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
291 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# KEYS.BAS | ||
|
||
Library to check for keys being pressed. It provide functions which are | ||
much faster than [INKEY$](../inkey.md), take less memory and does not require | ||
the Sinclair ROM to be present. | ||
|
||
## Functions | ||
Functions provided in this library: | ||
|
||
* [GetKey](./keys/getkey.md) | ||
* [GetKeyScanCode](./keys/getkeyscancode.md) | ||
* [MultiKeys](./keys/multikeys.md) | ||
|
||
|
||
### Scan codes | ||
|
||
This library define some global constants named _Scan codes_ which are just | ||
UInteger constant. | ||
|
||
Each key has assigned a unique Scan code. The ZX Spectrum Keyboard is divided | ||
in 8 Rows half. Each Row half comprises 5 keys (from the left or right side of the speccy | ||
QWERTY keyboard). | ||
|
||
For example letters H, J, K L and ENTER belong to row half #2 (see below). | ||
|
||
It is possible, for some routines, to use more than one scan code simultaneously, with `bOR` | ||
operator. | ||
For example `KEYH bOR KEYL` means Key H and/or Key L. | ||
The only restriction is that both keys must be in the same Row Half. | ||
|
||
These are all the scan codes available and their values. | ||
``` | ||
Scan Codes | ||
1st Keyboard ROW half | ||
const KEYB AS UInteger = 07F10h | ||
const KEYN AS UInteger = 07F08h | ||
const KEYM AS UInteger = 07F04h | ||
const KEYSYMBOL AS UInteger = 07F02h | ||
const KEYSPACE AS UInteger = 07F01h | ||
2nd Keyboard ROW half | ||
const KEYH AS UInteger = 0BF10h | ||
const KEYJ AS UInteger = 0BF08h | ||
const KEYK AS UInteger = 0BF04h | ||
const KEYL AS UInteger = 0BF02h | ||
const KEYENTER AS UInteger = 0BF01h | ||
REM 3rd Keyboard ROW half | ||
const KEYY AS UInteger = 0DF10h | ||
const KEYU AS UInteger = 0DF08h | ||
const KEYI AS UInteger = 0DF04h | ||
const KEYO AS UInteger = 0DF02h | ||
const KEYP AS UInteger = 0DF01h | ||
REM 4th Keyboard ROW half | ||
const KEY6 AS UInteger = 0EF10h | ||
const KEY7 AS UInteger = 0EF08h | ||
const KEY8 AS UInteger = 0EF04h | ||
const KEY9 AS UInteger = 0EF02h | ||
const KEY0 AS UInteger = 0EF01h | ||
REM 5th Keyboard ROW half | ||
const KEY5 AS UInteger = 0F710h | ||
const KEY4 AS UInteger = 0F708h | ||
const KEY3 AS UInteger = 0F704h | ||
const KEY2 AS UInteger = 0F702h | ||
const KEY1 AS UInteger = 0F701h | ||
REM 6th Keyboard ROW half | ||
const KEYT AS UInteger = 0FB10h | ||
const KEYR AS UInteger = 0FB08h | ||
const KEYE AS UInteger = 0FB04h | ||
const KEYW AS UInteger = 0FB02h | ||
const KEYQ AS UInteger = 0FB01h | ||
REM 7th Keyboard ROW half | ||
const KEYG AS UInteger = 0FD10h | ||
const KEYF AS UInteger = 0FD08h | ||
const KEYD AS UInteger = 0FD04h | ||
const KEYS AS UInteger = 0FD02h | ||
const KEYA AS UInteger = 0FD01h | ||
REM 8th Keyboard ROW half | ||
const KEYV AS UInteger = 0FE10h | ||
const KEYC AS UInteger = 0FE08h | ||
const KEYX AS UInteger = 0FE04h | ||
const KEYZ AS UInteger = 0FE02h | ||
const KEYCAPS AS UInteger = 0FE01h | ||
``` | ||
|
||
## See Also | ||
|
||
* [INKEY$](../inkey.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# GetKey | ||
|
||
Library: `#include <keys.bas>` | ||
|
||
Wait for a key to be pressed (using [INKEY$](../../inkey.md)), and return its ASCII Code. | ||
|
||
|
||
### Syntax | ||
`GetKey()` | ||
|
||
Waits for a key pressed and returns its ASCII code. It cannot detect multiple keys pressed. | ||
This is useful, for example, to program options menus in games were only a single option | ||
can be selected. | ||
|
||
## Examples | ||
|
||
``` | ||
#include <keys.bas> | ||
PRINT "PRESS A KEY" | ||
x = GetKey | ||
PRINT "You pressed the "; CHR x; " key" | ||
``` | ||
Will print the key pressed. Unlike [INKEY$](../../inkey.md) it returns an Ubyte (ASCII code) | ||
which is more efficent that working with strings. | ||
|
||
### See also | ||
|
||
* [GetKeyScanCode](getkeyscancode.md) | ||
* [MultiKeys](multikeys.md) | ||
|
||
|
||
Back to parent page: [String library](../keys.bas.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# MultiKeys | ||
|
||
Library: `#include <keys.bas>` | ||
|
||
Returns whether any of the given keys is being pressed. | ||
Unlike [INKEY$](../../inkey.md), it can detect multiple keys pressed at once | ||
(with some restrictions). | ||
|
||
|
||
### Syntax | ||
`MultiKeys(KeyCode1 bOR KeyCode2 bOR ...)` | ||
|
||
Returns whether any of the given keys was pressed. If no key was pressed, returns 0. | ||
It's possible to check for more than one key pressed at once, and to decode | ||
which keys were pressed by examining the returned value. | ||
|
||
## Examples | ||
|
||
``` | ||
#include <keys.bas> | ||
DO | ||
LOOP UNTIL MultiKeys(KEYH bOR KEYL) | ||
PAUSE 10 'Needed to allow the user to wait press 2 keys | ||
x = MultiKeys(KEYH bOR KEYL) | ||
IF x bAND KEYH PRINT "Key H was pressed" | ||
IF x bAND KEYL PRINT "Key L was pressed" | ||
``` | ||
Will print whether the Key H o the Key L or both bas been pressed. | ||
|
||
Checking for 2 or more keys will work only if these keys are in the same | ||
"row half", that is: in the same row and in the same group of 5 keys of that | ||
row (the left one or the right one) | ||
|
||
### See also | ||
|
||
* [GetKey](getkey.md) | ||
* [GetKeyScanCode](.getkeyscancode.md) | ||
|
||
|
||
Back to parent page: [String library](../keys.bas.md) |
Oops, something went wrong.