---
title: crwdns60516:0crwdne60516:0
image: crwdns60518:0crwdne60518:0
---
## crwdns60520:0crwdne60520:0
crwdns60522:0crwdne60522:0
crwdns60524:0crwdne60524:0
crwdns60526:0crwdne60526:0
## crwdns60528:0crwdne60528:0
crwdns60530:0crwdne60530:0
crwdns60532:0crwdne60532:0
## crwdns60534:0crwdne60534:0
crwdns60536:0crwdne60536:0
1. crwdns60538:0#what-is-a-hotkey-scope-crwdne60538:0
2. crwdns60540:0crwdne60540:0
crwdns60542:0crwdne60542:0
## crwdns60544:0crwdne60544:0
crwdns60546:0crwdne60546:0
1. crwdns60548:0crwdne60548:0
2. crwdns60550:0crwdne60550:0
crwdns60552:0crwdne60552:0
### crwdns60554:0crwdne60554:0
crwdns60556:0crwdne60556:0
```tsx
const PageListeningEnter = () => {
const {
setHotkeyScopeAndMemorizePreviousScope,
goBackToPreviousHotkeyScope,
} = usePreviousHotkeyScope();
// 1. Set the hotkey scope in a useEffect
useEffect(() => {
setHotkeyScopeAndMemorizePreviousScope(
ExampleHotkeyScopes.ExampleEnterPage,
);
// Revert to the previous hotkey scope when the component is unmounted
return () => {
goBackToPreviousHotkeyScope();
};
}, [goBackToPreviousHotkeyScope, setHotkeyScopeAndMemorizePreviousScope]);
// 2. Use the useScopedHotkeys hook
useScopedHotkeys(
Key.Enter,
() => {
// Some logic executed on this page when the user presses Enter
// ...
},
ExampleHotkeyScopes.ExampleEnterPage,
);
return
My page that listens for Enter
;
};
```
### crwdns60558:0crwdne60558:0
crwdns60560:0crwdne60560:0
crwdns60562:0crwdne60562:0
```tsx
const ExamplePageWithModal = () => {
const [showModal, setShowModal] = useState(false);
const {
setHotkeyScopeAndMemorizePreviousScope,
goBackToPreviousHotkeyScope,
} = usePreviousHotkeyScope();
const handleOpenModalClick = () => {
// 1. Set the hotkey scope when user opens the modal
setShowModal(true);
setHotkeyScopeAndMemorizePreviousScope(
ExampleHotkeyScopes.ExampleModal,
);
};
const handleModalClose = () => {
// 1. Revert to the previous hotkey scope when the modal is closed
setShowModal(false);
goBackToPreviousHotkeyScope();
};
return
My page with a modal
{showModal && }
;
};
```
crwdns60564:0crwdne60564:0
```tsx
const MyDropdownComponent = ({ onClose }: { onClose: () => void }) => {
// 2. Use the useScopedHotkeys hook to listen for Escape.
// Note that escape is a common hotkey that could be used by many other components
// So it's important to use a hotkey scope to avoid conflicts
useScopedHotkeys(
Key.Escape,
() => {
onClose()
},
ExampleHotkeyScopes.ExampleModal,
);
return