Shortcut Key Development
When to Use
You can set the delay for starting an ability using the shortcut key. An example is to take a screenshot 5 seconds after the shortcut key is pressed.
Modules to Import
import shortKey from '@ohos.multimodalInput.shortKey';
Available APIs
The following table lists common APIs for event injection. For details about the APIs, see ohos.multimodalInput.shortKey.
API | Description |
---|---|
setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback<void>): void | Sets the delay for starting an ability using the shortcut key. |
How to Develop
The following describes how to take a screenshot five seconds after the shortcut key is pressed.
import shortKey from '@ohos.multimodalInput.shortKey';
try {
shortKey.setKeyDownDuration("screenshot", 500, (error) => {// Set the delay to 5 seconds (500 ms)
if (error) {
console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Set key down duration success`);
});
} catch (error) {
console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}