Go to the source code of this file.
Data Structures | |
union | keymatrix |
A matrix of simultaneous key states. More... | |
Defines | |
#define | KB_A 41 |
Constant for the F1 (A) key. | |
#define | KB_B 42 |
Constant for the F2 (B) key. | |
#define | KB_C 43 |
Constant for the F3 (C) key. | |
#define | KB_D 44 |
Constant for the F4 (D) key. | |
#define | KB_E 45 |
Constant for the F5 (E) key. | |
#define | KB_F 46 |
Constant for the F6 (F) key. | |
#define | KB_G 47 |
Constant for the APPS (G) key. | |
#define | KB_H 53 |
Constant for the MODE (H) key. | |
#define | KB_I 54 |
Constant for the TOOL (I) key. | |
#define | KB_J 55 |
Constant for the VAR (J) key. | |
#define | KB_K 57 |
Constant for the STO (K) key. | |
#define | KB_L 58 |
Constant for the NXT (L) key. | |
#define | KB_M 33 |
Constant for the HIST (M) key. | |
#define | KB_N 25 |
Constant for the EVAL (N) key. | |
#define | KB_O 17 |
Constant for the ' (O) key. | |
#define | KB_P 9 |
Constant for the SYMB (P) key. | |
#define | KB_Q 34 |
Constant for the Y^X (Q) key. | |
#define | KB_R 26 |
Constant for the Sqrt (R) key. | |
#define | KB_S 18 |
Constant for the SIN (S) key. | |
#define | KB_T 10 |
Constant for the COS (T) key. | |
#define | KB_U 2 |
Constant for the TAN (U) key. | |
#define | KB_V 35 |
Constant for the EEX (V) key. | |
#define | KB_W 27 |
Constant for the +/- (W) key. | |
#define | KB_X 19 |
Constant for the X (X) key. | |
#define | KB_Y 11 |
Constant for the 1/X (Y) key. | |
#define | KB_Z KB_DIV |
Constant for the / (Z) key. | |
#define | KB_0 31 |
Constant for the 0 key. | |
#define | KB_1 30 |
Constant for the 1 key. | |
#define | KB_2 22 |
Constant for the 2 key. | |
#define | KB_3 14 |
Constant for the 3 key. | |
#define | KB_4 29 |
Constant for the 4 key. | |
#define | KB_5 21 |
Constant for the 5 key. | |
#define | KB_6 13 |
Constant for the 6 key. | |
#define | KB_7 28 |
Constant for the 7 key. | |
#define | KB_8 20 |
Constant for the 8 key. | |
#define | KB_9 12 |
Constant for the 9 key. | |
#define | KB_BKS 1 |
Constant for the backspace key. | |
#define | KB_DIV 3 |
Constant for the / (Z) key. | |
#define | KB_MUL 4 |
Constant for the * key. | |
#define | KB_ADD 6 |
Constant for the + key. | |
#define | KB_SUB 5 |
Constant for the - key. | |
#define | KB_DOT 23 |
Constant for the . key. | |
#define | KB_SPC 15 |
Constant for the SPC key. | |
#define | KB_ENT 7 |
Constant for the ENT key. | |
#define | KB_UP 49 |
Constant for the up arrow key. | |
#define | KB_DN 51 |
Constant for the down arrow key. | |
#define | KB_LF 50 |
Constant for the left arrow key. | |
#define | KB_RT 52 |
Constant for the right arrow key. | |
#define | KB_ALPHA 60 |
Constant for the ALPHA key. | |
#define | KB_LSHIFT 61 |
Constant for the left shift key. | |
#define | KB_RSHIFT 62 |
Constant for the right shift key. | |
#define | KB_ON 63 |
Constant for the ON key. | |
#define | KB_MASK64(a) (((ULONGLONG)1)<<(a)) |
Create a bitmask representing the given key. | |
#define | KB_MASK32(a) (((unsigned int)1)<<(a&31)) |
Create a bitmask representing the given key (32-bit). | |
#define | KB_MASK8(a) (((unsigned int)1)<<(a&7)) |
Create a bitmask representing the given key (8-bit). | |
#define | KB_CURS ((ULONGLONG)0x001e000000000000) |
A bitmask to represent the arrow keys. | |
#define | KBH_CURS32 ((unsigned int)0x001e0000) |
A bitmask to represent the arrow keys (32-bit). | |
#define | KB_FUNC ((ULONGLONG)0x00007e0000000000) |
A bitmask to represent the function keys. | |
#define | KBH_FUNC32 ((unsigned int)0x00007e00) |
A bitmask to represent the function keys (32-bit). | |
#define | SHFT_LS 0x40000000 |
Shift constant to use in a combined shiftcode. Left Shift. | |
#define | SHFT_RS 0x20000000 |
Shift constant to use in a combined shiftcode. Right Shift. | |
#define | SHFT_ALPHA 0x10000000 |
Shift constant to use in a combined shiftcode. Alpha. | |
#define | SHFT_ON 0x80000000 |
Shift constant to use in a combined shiftcode. On key. | |
#define | SHFT_ANY 0xf0000000 |
Shift constant to use in a combined shiftcode. Any Shift or ON. | |
#define | KEYCODE(shftcode) ((shftcode)&0xff) |
Extracts a keycode from a combined shiftcode. | |
#define | SHFTPLANE(shftcode) ((shftcode)&0xf0000000) |
Extracts shift plane from a combined shiftcode. | |
#define | WAIT_CANCEL {while(keyb_isON()); while(! keyb_isON());} |
Typedefs | |
typedef unsigned long long | ULONGLONG |
typedef long long | LONGLONG |
Functions | |
int | keyb_isKeyPressed (unsigned char col, unsigned char row) |
Tests the current state of a key. | |
int | keyb_isAnyKeyPressed (void) |
Tests whether any key is being pressed on the keyboard. | |
void | keyb_waitKeyPressed (void) |
Waits for a key to be pressed. | |
int | keyb_isLeft (void) |
Tests if the left arrow key is down. | |
int | keyb_isRight (void) |
Tests if the right arrow key is down. | |
int | keyb_isUp (void) |
Tests if the up arrow key is down. | |
int | keyb_isDown (void) |
Tests if the down arrow key is down. | |
int | keyb_isAlpha (void) |
Tests if the alpha key is down. | |
int | keyb_isLS (void) |
Tests if the left shift key is down. | |
int | keyb_isRS (void) |
Tests if the right shift key is down. | |
int | keyb_isON (void) |
Tests if the on key is down. | |
int | keyb_getkey (int wait) |
Returns an identifier for the first key pressed. | |
void | keyb_getmatrix (keymatrix *ptr) |
Retrieves the state of the complete keyboard. | |
int | keyb_isKeyPrM (int keycode) |
Tests the current state of a key. Keymatrix version. | |
int | keyb_isShiftKeyPrM (int shiftcode) |
Tests the current state of a key with shift plane. | |
int | keyb_getkeyM (int wait) |
Returns the shiftcode for the first key pressed. | |
int | keyb_getnextkey (keymatrix *ptr, int keycode) |
Gets the keycode for the next key pressed in a key combination. |
Interaction with the calculator keyboard can be done at a high level, or a low level. Functions defined in this file are used to interact at a low level with the calculator keyboard. For higher-level user input routines, see getchar, gets, getkey, readint, readuint, readhex, readlonglong, readulonglong, and readdouble.
At the moment, keys are identified in various hodge-podge manners by the various functions defined in this file. Here is a compilation of them all. Logical rows and columns are for the HP49G+; these values probably apply to the HP48gII as well, but this fact has not been verified. The HP39G+ has a somewhat different keyboard layout, which is not yet documented.
Definition in file hpkeyb49.h.
#define KB_0 31 |
#define KB_1 30 |
#define KB_2 22 |
#define KB_3 14 |
#define KB_4 29 |
#define KB_5 21 |
#define KB_6 13 |
#define KB_7 28 |
#define KB_8 20 |
#define KB_9 12 |
#define KB_A 41 |
#define KB_ADD 6 |
#define KB_ALPHA 60 |
#define KB_B 42 |
#define KB_BKS 1 |
#define KB_C 43 |
#define KB_CURS ((ULONGLONG)0x001e000000000000) |
A bitmask to represent the arrow keys.
The keymatrix::full field of a keymatrix can be combined with this mask via a bitwise and (&) to eliminate everything except the state of the arrow keys (aka cursor keys). This is a convenience constant, and its value is equivalent to: KB_MASK64(KB_UP)
|
KB_MASK64(KB_DN)
|
KB_MASK64(KB_LF)
|
KB_MASK64(KB_RT)
.
Definition at line 466 of file hpkeyb49.h.
#define KB_D 44 |
#define KB_DIV 3 |
#define KB_DN 51 |
#define KB_DOT 23 |
#define KB_E 45 |
#define KB_ENT 7 |
#define KB_F 46 |
#define KB_FUNC ((ULONGLONG)0x00007e0000000000) |
A bitmask to represent the function keys.
The keymatrix::full field of a keymatrix can be combined with this mask via a bitwise and (&) to eliminate everything except the state of the function keys. This is a convenience constant, and its value is equivalent to: KB_MASK64(KB_A)
|
KB_MASK64(KB_B)
|
KB_MASK64(KB_C)
|
KB_MASK64(KB_D)
|
KB_MASK64(KB_E)
|
KB_MASK64(KB_F)
.
Definition at line 490 of file hpkeyb49.h.
#define KB_G 47 |
#define KB_H 53 |
#define KB_I 54 |
#define KB_J 55 |
#define KB_K 57 |
#define KB_L 58 |
#define KB_LF 50 |
#define KB_LSHIFT 61 |
#define KB_M 33 |
#define KB_MASK32 | ( | a | ) | (((unsigned int)1)<<(a&31)) |
Create a bitmask representing the given key (32-bit).
The bitmask returned by this macro can be compared with the keymatrix::hiword or keymatrix::loword field of a keymatrix result. When the key is known, it's more efficient to compare a 32-bit number than a 64-bit number.
Definition at line 443 of file hpkeyb49.h.
#define KB_MASK64 | ( | a | ) | (((ULONGLONG)1)<<(a)) |
Create a bitmask representing the given key.
The bitmask returned by this macro can be compared with the keymatrix::full field of a keymatrix result.
Definition at line 434 of file hpkeyb49.h.
#define KB_MASK8 | ( | a | ) | (((unsigned int)1)<<(a&7)) |
Create a bitmask representing the given key (8-bit).
The bitmask returned by this macro can be compared with the keymatrix::bytes[] field of a keymatrix result. When the column of the key is known, single-byte comparisons might be more efficient than a 64-bit number.
Definition at line 452 of file hpkeyb49.h.
#define KB_MUL 4 |
#define KB_N 25 |
#define KB_O 17 |
#define KB_ON 63 |
#define KB_P 9 |
#define KB_Q 34 |
#define KB_R 26 |
#define KB_RSHIFT 62 |
#define KB_RT 52 |
#define KB_S 18 |
#define KB_SPC 15 |
#define KB_SUB 5 |
#define KB_T 10 |
#define KB_U 2 |
#define KB_UP 49 |
#define KB_V 35 |
#define KB_W 27 |
#define KB_X 19 |
#define KB_Y 11 |
#define KB_Z KB_DIV |
#define KBH_CURS32 ((unsigned int)0x001e0000) |
A bitmask to represent the arrow keys (32-bit).
The keymatrix::hiword field of a keymatrix can be combined with this mask via a bitwise and (&) to eliminate everything except the state of the arrow keys (aka cursor keys). This is a convenience constant, and its value is equivalent to: KB_MASK32(KB_UP)
|
KB_MASK32(KB_DN)
|
KB_MASK32(KB_LF)
|
KB_MASK32(KB_RT)
.
Definition at line 478 of file hpkeyb49.h.
#define KBH_FUNC32 ((unsigned int)0x00007e00) |
A bitmask to represent the function keys (32-bit).
The keymatrix::hiword field of a keymatrix can be combined with this mask via a bitwise and (&) to eliminate everything except the state of the function keys. This is a convenience constant, and its value is equivalent to: KB_MASK64(KB_A)
|
KB_MASK64(KB_B)
|
KB_MASK64(KB_C)
|
KB_MASK64(KB_D)
|
KB_MASK64(KB_E)
|
KB_MASK64(KB_F)
.
Definition at line 501 of file hpkeyb49.h.
#define KEYCODE | ( | shftcode | ) | ((shftcode)&0xff) |
#define SHFT_ALPHA 0x10000000 |
#define SHFT_ANY 0xf0000000 |
Shift constant to use in a combined shiftcode. Any Shift or ON.
Definition at line 515 of file hpkeyb49.h.
#define SHFT_LS 0x40000000 |
Shift constant to use in a combined shiftcode. Left Shift.
Definition at line 507 of file hpkeyb49.h.
#define SHFT_ON 0x80000000 |
#define SHFT_RS 0x20000000 |
Shift constant to use in a combined shiftcode. Right Shift.
Definition at line 509 of file hpkeyb49.h.
#define SHFTPLANE | ( | shftcode | ) | ((shftcode)&0xf0000000) |
#define WAIT_CANCEL {while(keyb_isON()); while(! keyb_isON());} |
Definition at line 646 of file hpkeyb49.h.
typedef long long LONGLONG |
Definition at line 42 of file hpkeyb49.h.
typedef unsigned long long ULONGLONG |
Definition at line 41 of file hpkeyb49.h.
int keyb_getkey | ( | int | wait | ) |
Returns an identifier for the first key pressed.
Optionally waits for a key to be pressed, and then returns an identifier specifying which key was pressed. The identifier is calculated from the logical row and column of the key, according to the formula col
*
0xf
+
row
.
If the wait parameter is non-zero, this function does not return until a key has been completely pressed and released. If multiple keys are pressed simultaneously, the function does not return until all keys have been released; but the return value will be the identifier of the first key. If the wait parameter is zero, the function will wait neither for a key to be pressed or released.
wait | If 0, return a -1 identifier if no key is pressed; If non-zero, wait until a key is pressed. |
int keyb_getkeyM | ( | int | wait | ) |
Returns the shiftcode for the first key pressed.
Optionally waits for a non-shift key to be pressed, and then returns a shiftcode specifying which key was pressed and the shift state.
If the wait parameter is non-zero, this function does not return until a key has been completely pressed and released (only the key, shift can remain pressed). If multiple keys are pressed simultaneously, the function does not return until all keys have been released; but the return value will be the identifier of the first key. If the wait parameter is zero, the function will wait neither for a key to be pressed or released. The ON key is detected as a normal key, but Shift-ON is not detected.
wait | If 0, return a 0 identifier if no key is pressed; If non-zero, wait until a key is pressed. |
void keyb_getmatrix | ( | keymatrix * | ptr | ) |
Retrieves the state of the complete keyboard.
This function retrieves the state of the entire keyboard in one operation. The result can then be inspected using the various KB_*
preprocessor macros and constants.
ptr | A pointer to a keymatrix, which will hold the result. |
int keyb_getnextkey | ( | keymatrix * | ptr, | |
int | keycode | |||
) |
Gets the keycode for the next key pressed in a key combination.
When multiple keys are expected to be pressed at the same time, this function aids in detecting all the keys correctly. Given a keymatrix, this function returns the keycode of the next key pressed in the matrix, or 0 when no more keys are pressed. Notice that the keyboard is not read by this function. A valid keymatrix is expected as an input argument. To use this function: keymatrix mat; keyb_getmatrix(&mat); // read keyboard int key=keyb_getnextkey(&mat,-1); // get first key while (key!=0) { ... process the key ... key=keyb_getnextkey(&mat,key); // get the next keycode }
ptr | Pointer to the keymatrix to be processed. | |
keycode | Keycode of the last key returned by this function. Use -1 to retrieve the first key in the group. |
int keyb_isAlpha | ( | void | ) |
Tests if the alpha key is down.
int keyb_isAnyKeyPressed | ( | void | ) |
Tests whether any key is being pressed on the keyboard.
int keyb_isDown | ( | void | ) |
Tests if the down arrow key is down.
This is a convenience function. It behaves exactly like keyb_isKeyPressed (6,2) does.
int keyb_isKeyPressed | ( | unsigned char | col, | |
unsigned char | row | |||
) |
Tests the current state of a key.
The key to be tested is identified by the row and col parameters. These parameters, however, do not identify the physical position of the key on the keyboard. Instead, they refer to the key's "logical" position. Refer to the documentation for the header file hpkeyb49.h for a list of keys with their logical rows and columns.
Certain keys, namely ON, ALPHA, and both shift keys, cannot be tested with this function. Instead, please use keyb_isON, keyb_isAlpha, keyb_isLS, and keyb_isRS to test these keys. As a convenience, the functions keyb_isLeft, keyb_isRight, keyb_isUp, and keyb_isDown are also provided, although those keys can be tested using this function as well.
col | The logical column of the key to test. | |
row | The logical row of the key to test. |
int keyb_isKeyPrM | ( | int | keycode | ) |
Tests the current state of a key. Keymatrix version.
This function detects if a key is pressed. Unlike the row/column version, (keyb_isKeyPressed) this routine can detect all the keys.
keycode | The KB_... constant of a key. |
int keyb_isLeft | ( | void | ) |
Tests if the left arrow key is down.
This is a convenience function. It behaves exactly like keyb_isKeyPressed (6,1) does.
int keyb_isLS | ( | void | ) |
Tests if the left shift key is down.
int keyb_isON | ( | void | ) |
Tests if the on key is down.
int keyb_isRight | ( | void | ) |
Tests if the right arrow key is down.
This is a convenience function. It behaves exactly like keyb_isKeyPressed (6,3) does.
int keyb_isRS | ( | void | ) |
Tests if the right shift key is down.
int keyb_isShiftKeyPrM | ( | int | shiftcode | ) |
Tests the current state of a key with shift plane.
This function detects if a shifted key is pressed.
shiftcode | The KB_... constant of a key, combined (OR '|') with one or more SHFT_... constants. For example, to detect Left-Shift A, the argument should be KB_A | SHFT_LS |
int keyb_isUp | ( | void | ) |
Tests if the up arrow key is down.
This is a convenience function. It behaves exactly like keyb_isKeyPressed (6,0) does.
void keyb_waitKeyPressed | ( | void | ) |
Waits for a key to be pressed.
This convenience function waits for a key to be completely pressed and released. It can be used to wait for user acknowledgement of some kind. Because the function does not return until the key has been released, it can be used without worrying about the key registering later in the application code.