Key pressed
A decision block that awaits a key/button press or release.
The fiber will pause until a key has been pressed proceeding through the YES path,
or a key was released proceeding through the UP path.
- Virtual keyboards generally don’t generate key presses.
- Detecting hardware buttons such as power and volume may not work, or only do so when the screen is on.
- Detecting volume key long presses on Android 8+ requires the “intercept volume key long press” privilege,
the Long press flag, and that consume is enabled.
The Unicode and dead character codes are used to convert key presses to readable text.
If the dead code is not null
then it needs to be combined with the Unicode of the next key pressed using the undead function.
If the Unicode is not null
and the previous key press had no dead code then simply use the char function to convert it to text.
To handle both cases with the result as text
use an expression like char(previousDeadChar ? undead(previousDeadChar, currentUnicodeChar) : currentUnicodeChar)
on each key press, i.e. the YES path.
Input arguments
- Key codes — a single key code number, or an array of key codes to await, default is all.
- Key modifiers — modifiers which must be in effect, default is to ignore modifiers.
- Flags — flags of event to include, default is to ignore flags.
- Consume — filter the key press from other app. Some key codes can’t be filtered.
Output variables
- Pressed key code — variable to assign the key code to pressed key.
- Pressed key modifiers — variable to assign the key modifiers in effect.
- Unicode character code — variable to assign the Unicode character code of the pressed key if there is such, otherwise
null
.
- Dead character code — variable to assign the character code of pressed key if it’s a “dead” key that should be combined with the next Unicode character, otherwise
null
.