mirror of
https://github.com/processing/processing4.git
synced 2026-02-12 01:50:44 +01:00
87 lines
1.3 KiB
XML
87 lines
1.3 KiB
XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
<root>
|
|
<name>key</name>
|
|
|
|
<category>Input/Output</category>
|
|
|
|
<subcategory>Keyboard</subcategory>
|
|
|
|
<usage>Web & Application</usage>
|
|
|
|
<example>
|
|
<image>key.jar</image>
|
|
<code>
|
|
// Click on the window to give it focus
|
|
// and press the 'B' key
|
|
|
|
void loop() {
|
|
if(keyPressed) {
|
|
if (key == 'b' || key == 'B') {
|
|
fill(0);
|
|
}
|
|
} else {
|
|
fill(255);
|
|
}
|
|
rect(25, 25, 50, 50);
|
|
}
|
|
</code>
|
|
</example>
|
|
|
|
<example>
|
|
<image>key2.jar</image>
|
|
<code>
|
|
// Click on the window to give it focus
|
|
// and press the up and down arrow keys
|
|
|
|
void loop() {
|
|
if(keyPressed) {
|
|
if (key == UP) {
|
|
fill(255);
|
|
} else if (key == DOWN) {
|
|
fill(0);
|
|
}
|
|
} else {
|
|
fill(126);
|
|
}
|
|
rect(25, 25, 50, 50);
|
|
}
|
|
</code>
|
|
</example>
|
|
|
|
<description>
|
|
The system variable <b>key</b> always contains the value of the most recently pressed key on the keyboard. For detecting the arrow keys, the <b>key</b> variable is set to either UP, DOWN, LEFT, or RIGHT. Other special key constants are ALT, CONTROL, and SHIFT.
|
|
</description>
|
|
|
|
<syntax>
|
|
key
|
|
</syntax>
|
|
|
|
<parameter>
|
|
<label></label>
|
|
<description></description>
|
|
</parameter>
|
|
|
|
<returns></returns>
|
|
|
|
<related>
|
|
keyPressed
|
|
keyCode
|
|
keyPressed()
|
|
keyReleased()
|
|
</related>
|
|
|
|
<availability>1.0</availability>
|
|
|
|
<type>System variable</type>
|
|
|
|
<partof>Core</partof>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</root>
|