GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Processing
  • p5.js
  • Processing.py
  • Processing for Android
  • Processing for Pi
  • Processing Foundation

This view

  • Original page
  • New address

GeezerVison is showing py.processing.org — keyCode \ Language (API)

Python Mode for Processing is no longer maintained. This site is kept as an archive. Read more
  • Processing
  • p5.js
  • Processing.py
  • Processing for Android
  • Processing for Pi
  • Processing Foundation
Cover
Reference
Tutorials
Examples
Bugs
Name

keyCode

Examples
fillVal = color(126)


def draw():
    fill(fillVal)
    rect(25, 25, 50, 50)


def keyPressed():
	global fillVal
    if key == CODED:
        if keyCode == UP:
            fillVal = 255
        elif keyCode == DOWN:
            fillVal = 0
    else:
        fillVal = 126

THIS EXAMPLE IS BROKEN

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.
Related key
keyPressed
keyPressed()
keyReleased()

Updated on Sat Oct 24 11:26:09 2026.

If you see any errors or have comments, please let us know.

Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.