Hardware Reference
In-Depth Information
When initialized, this class calls two functions when a specii ed event occurs.
There are two events that can be identii ed by the class outside loop() : when a
key is pressed and when a key is released. These do not include modii er keys;
Shift, Control, Alt, and other such keys do not call these functions, but Caps
Lock does.
The two functions are keyPressed() and keyReleased() . No parameters are
passed to these functions; they must retrieve pending information from other sources.
// This function is called when a key is pressed
void keyPressed()
{
Serial.print("Key pressed");
}
This tells the sketch that a key has been pressed or released, but that is all.
To know which key or combination of keys has been pressed, use getKey() .
result = keyboard.getKey();
This function takes no parameters and returns the ASCII code of the key
pressed. Not all keys can be printed as ASCII, and for this reason, another
function is available, getOemKey() .
result = getOemKey();
This function, unlike getKey() , does not return an ASCII code, but the OEM
code associated with this key. This key can be one of the function keys or a
multimedia key. It does not work on modii er keys: Shift, Alt, AltGr, Control,
and so on. To get the status of modii er keys, use getModifiers() :
result = keyboard.getModifiers();
This function returns an int , representing a bit i eld with modii ers, listed
in Table 20-1.
Table 20-1: Modifi er values
MODIFIER KEY
VALUE
LeftCtrl
1
LeftShift
2
Alt
4
LeftCmd
8
RightCtrl
16
RightShift
32
AltGr
64
RightCmd
128
Search WWH ::




Custom Search