key-as-keyword

key-code

key-coded?

key-modifiersclj

key-pressed?

raw-key

key-as-keyword

Arguments
[]
Docstring

Returns a keyword representing the currently pressed key. Modifier keys are represented as: :up, :down, :left, :right, :alt, :control, :shift, :command, :f1-24

Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn] [[0 "key-as-keyword" q/key-as-keyword]
                           [1 "key-code" q/key-code]
                           [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
                           [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]
                           [5 "key-modifiers" q/key-modifiers]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn]
              [[0 "key-as-keyword" q/key-as-keyword] [1 "key-code" q/key-code]
               [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
               [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
    try example

key-code

Arguments
[]
Docstring

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 (= (key) CODED).

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 key-code. 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.

For users familiar with Java, the values for UP and DOWN are simply shorter versions of Java's KeyEvent.VK_UP and KeyEvent.VK_DOWN. Other keyCode values can be found in the Java KeyEvent reference.

Works only inside sketch functions?
Yes
Original Processing method
keyCode
Original p5js method
keyCode
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn] [[0 "key-as-keyword" q/key-as-keyword]
                           [1 "key-code" q/key-code]
                           [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
                           [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]
                           [5 "key-modifiers" q/key-modifiers]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn]
              [[0 "key-as-keyword" q/key-as-keyword] [1 "key-code" q/key-code]
               [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
               [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
    try example

key-coded?

Arguments
[c]
Docstring

Returns true if char c is a coded char i.e. it is necessary to fetch the key-code as an integer and use that to determine the specific key pressed. See key-as-keyword.

Works only inside sketch functions?
No
Original Processing method
None.
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn] [[0 "key-as-keyword" q/key-as-keyword]
                           [1 "key-code" q/key-code]
                           [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
                           [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]
                           [5 "key-modifiers" q/key-modifiers]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn]
              [[0 "key-as-keyword" q/key-as-keyword] [1 "key-code" q/key-code]
               [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
               [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
    try example

key-modifiersclj

Arguments
[]
Docstring

Set of key modifiers that were pressed when event happened. Possible modifiers :ctrl, :alt, :shift, :meta. Not available in ClojureScript.

Works only inside sketch functions?
Yes
Original Processing method
None.
Original p5js method
None.
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn] [[0 "key-as-keyword" q/key-as-keyword]
                           [1 "key-code" q/key-code]
                           [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
                           [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]
                           [5 "key-modifiers" q/key-modifiers]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn]
              [[0 "key-as-keyword" q/key-as-keyword] [1 "key-code" q/key-code]
               [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
               [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
    try example

key-pressed?

Arguments
[]
Docstring

true if any key is currently pressed, false otherwise.

Works only inside sketch functions?
Yes
Original Processing method
keyPressed
Original p5js method
keyIsPressed
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn] [[0 "key-as-keyword" q/key-as-keyword]
                           [1 "key-code" q/key-code]
                           [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
                           [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]
                           [5 "key-modifiers" q/key-modifiers]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn]
              [[0 "key-as-keyword" q/key-as-keyword] [1 "key-code" q/key-code]
               [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
               [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
    try example

raw-key

Arguments
[]
Docstring

Contains the value of the most recent key on the keyboard that was used (either pressed or released).

For non-ASCII keys, use the keyCode variable. 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.

Works only inside sketch functions?
Yes
Original Processing method
key
Original p5js method
key
Example
clojure specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn] [[0 "key-as-keyword" q/key-as-keyword]
                           [1 "key-code" q/key-code]
                           [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
                           [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]
                           [5 "key-modifiers" q/key-modifiers]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
clojurescript specific
  • (q/background 255)
    (q/fill 0)
    ; iterate through all key-related functions
    ; and print their values
    (doseq [[ind capt fn]
              [[0 "key-as-keyword" q/key-as-keyword] [1 "key-code" q/key-code]
               [2 "key-coded?" (fn* [] (q/key-coded? (q/raw-key)))]
               [3 "key-pressed?" q/key-pressed?] [4 "raw-key" q/raw-key]]]
      (q/text (str capt " " (fn)) 10 (+ (* 20 ind) 20)))
    try example