numkey

Interpret numbers typed on the computer keyboard

Description

numkey process key presses into numbers.

Arguments

Name Type Opt Description
output-format float opt A float argument causes numkey to understand the decimal point and the fractional part of a number, and send out floats instead of ints. (The argument does not, however, set an initial value for numkey. The initial value is always 0.)

Messages

bang Sends the number currently stored in numkey out the left outlet, and resets the stored number to 0.
int ASCII-value [int]
The number is an ASCII value received from a key or keyup object. When digits are typed on the computer keyboard, numkey recognizes the ASCII values and interprets them as the numbers being typed.

The keys recognized by numkey are the digits 0-9, the Delete (Backspace) key, decimal point (period), Return, and Enter. Digits are combined as a single number and stored in numkey.
clear Resets the stored number to 0.

Information for box attributes common to all objects

Output

float: When there is a float argument, numkey understands decimal points and fractional parts of a number, and sends out floats instead of ints.
int: When digits are typed on the computer keyboard, and the ASCII value (from key or keyup) is received in the inlet, the digits are combined as a single number and stored in numkey. The stored number is sent out the right outlet each time a new digit is typed. The Delete key on Macintosh or Backspace key on Windows erases the most recently typed digit, and sends the stored number out the right outlet. The period key acts as a decimal point and causes numkey not to store subsequent digits until a new number is started (unless there is a float argument). Typing the Return or Enter keys on Macintosh or the Enter key on Windows sends the stored number out the left outlet and resets the number stored in numkey to 0, so that a new number can be typed in.

Examples

Recognizes all numbers typed in

See Also

Name Description
key Report key presses on the computer keyboard
keyup Report key releases on the computer keyboard
number Display and output a number
Max Basic Tutorial 8: Keyboard and Mouse Input Max Basic Tutorial 8: Keyboard and Mouse Input