Name

keyCode

Examples
fillVal <- 126

draw <- function() {
    fill(fillVal)
    rect(25, 25, 50, 50)
}

keyPressed <- function() {
    # See https://github.com/gaocegege/Processing.R/issues/209
    if (key == CODED) {
        if (keyCode == UP) {
            fillVal = 255
        } else if (keyCode == DOWN) {
            fillVal = 0
        }
    } else {
        fillVal = 126
    }
}
Description The variable keyCode is used to detect special keys such as the UP, DOWN, LEFT, RIGHT arrow keys and ALT, CONTROL, SHIFT. When checking for these keys, it's first necessary to check and see if the key is coded. This is done with the conditional "if (key == CODED)" as shown in the example.

The keys included in the ASCII specification (BACKSPACE, TAB, ENTER, RETURN, ESC, and DELETE) do not require checking to see if they key is coded, and you should simply use the key variable instead of keyCode If you're making cross-platform projects, note that the ENTER key is commonly used on PCs and Unix and the RETURN key is used instead on Macintosh. Check for both ENTER and RETURN to make sure your program will work for all platforms.
Syntax
Related key
keyPressed_var
keyPressed
keyReleased
Creative Commons License