In the "while" cycle, use the function key= keypad.getKey () to read the keyboard constantly. If there is a key
pressed, its key code will be stored in the variable "key", then be printed out.
key = keypad. getKey(); //get the state of keys
if (key){ // if a key is pressed, print out its key code
printf("You Pressed key : %c \n", key);
}
}
The library Keypad used for RPi is transplanted from the Arduino library Keypad. And the source files can be
obtained by visiting http://playground.arduino.cc/Code/Keypad. As for transplanted function library, the
function and method of all classes, functions, variables, etc. are the same as the original library. Partial contents
of the Keypad library are described below:
Ke ypad(char *userKeymap, byte *row, byte * col, b yte n umRows, byte numCols);
Constructor, the parameters are: key code of keyboard, row pin, column pin, the number of rows, the
number of columns.
ch ar getKey();
Get the key code of the pressed key. If no key is pressed, the return value is NULL.
vo id setDebounceTime(uint);
Set the debounce time. And the default time is 10ms.
vo id setHoldTime(uint);
Set the time when the key holds stable state after pressed.
bo ol isPressed(char keyChar);
Judge wether the key with code "keyChar" is pressed.
ch ar waitForKey();
Wait for a key to be pressed, and return key code of the pressed key.
Ke yState g etState();
Get state of the keys.
bo ol keyStateChanged();
Judge whether there is a change of key state, then return True or False.
For More information about Keypad, please visit: http://playground.arduino.cc/Code/Keypad or through the
opening file "Keypad.hpp".