File: use-input.md | Updated: 11/16/2025
This hook is used for handling user input.
It's a more convenient alternative to using useStdin and listening for data events.
The callback you pass to useInput is called for each character when the user enters any input.
However, if the user pastes text and it's more than one character, the callback will be called only once, and the whole string will be passed as input.
import {useInput} from 'ink';
const UserInput = () => {
useInput((input, key) => {
if (input === 'q') {
// Exit program
}
if (key.leftArrow) {
// Left arrow key pressed
}
});
return …
};
You can find a full example of using useInput at examples/use-input.
Type: Function
The handler function that you pass to useInput receives two arguments:
Type: string
The input that the program received.
Type: object
Handy information about a key that was pressed.
Type: boolean
Default: false
If an arrow key was pressed, the corresponding property will be true.
For example, if the user presses the left arrow key, key.leftArrow equals true.
Type: boolean
Default: false
Return (Enter) key was pressed.
Type: boolean
Default: false
Escape key was pressed.
Type: boolean
Default: false
Ctrl key was pressed.
Type: boolean
Default: false
Shift key was pressed.
Type: boolean
Default: false
Tab key was pressed.
Type: boolean
Default: false
Backspace key was pressed.
Type: boolean
Default: false
Delete key was pressed.
Type: boolean
Default: false
If the Page Up or Page Down key was pressed, the corresponding property will be true.
For example, if the user presses Page Down, key.pageDown equals true.
Type: boolean
Default: false
Meta key was pressed.
Type: object
Type: boolean
Default: true
Enable or disable capturing of user input.
Useful when there are multiple useInput hooks used at once to avoid handling the same input several times.