-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) 2024. The Pycroft Authors. See the AUTHORS file. | ||
* This file is part of the Pycroft project and licensed under the terms of | ||
* the Apache License, Version 2.0. See the LICENSE file for details | ||
*/ | ||
|
||
function waitForKeyPress(callback: (event: KeyboardEvent) => void): void { | ||
const handleKeyPress = (event: KeyboardEvent) => { | ||
// Call the callback function with the event when a key is pressed | ||
callback(event); | ||
|
||
// Remove the event listener after the first key press (if you want it to happen only once) | ||
document.removeEventListener('keydown', handleKeyPress); | ||
}; | ||
|
||
// Add the event listener to the document | ||
document.addEventListener('keydown', handleKeyPress); | ||
} | ||
|
||
// Example of using the function | ||
waitForKeyPress((event) => { | ||
console.log(`Key pressed: ${event.key}`); | ||
// Add your logic here based on the key press | ||
}); |