Hardware Reference
In-Depth Information
The modii ers listed in this table have been created as constants, and as such,
can be used directly in your code.
mod = keyboard.getModifiers();
if (mod & LeftCtrl)
Serial.println("L-Ctrl");
Mice
Mice are just as easy to use as a keyboard, using similar techniques. To use a
USB mouse, you must attach the MouseController to the USB subsystem, just
like with a keyboard.
// Attach mouse controller to USB
MouseController mouse(usb);
Just like the keyboard controller, the mouse controller can also call functions.
There are four of them: when the mouse is moved, when the mouse is dragged,
when a button is pushed, and when a button is released.
void mouseMoved()
{
// Mouse has moved
}
void mouseDragged()
{
// Mouse was moved with a button pressed
}
void mousePressed()
{
// A mouse button has been pressed
}
void mouse Released()
{
// A pressed button has been released
}
To retrieve movement information, you use getXChange() and getYChange() .
Both return int values, indicating the relative change in direction since the last
time the mouse was polled.
Computer screens use a top-left coordinate system; the (0, 0) coordinate is
in the top-left side (see Figure 20-3). The x- coordinate increases when going
right and decreases when going left. The y- coordinate increases when going
downward and decreases when going upward.
 
Search WWH ::




Custom Search