There are two types of hotkeys: global and local.
- Global hotkeys work even when the application is inactive.
- Local hotkeys only work when the application is active.
The implementation for global hotkeys would be adapted from davedelong/DDHotKey.
The implementation for local hotkeys would use the RCTKeyCommands
class that already exists.
import {HotKey} from 'react-native-macos'
import {copy, paste} from 'my-app'
// Mount this component to enable the hotkeys inside.
const CopyPaste = () => (
<>
<HotKey bind="cmd+c" onPress={copy} />
<HotKey bind="cmd+p" onPress={paste} />
</>
)
Hotkeys are local by default. Use the global
prop to make them work when the app is inactive.
<HotKey global={true} bind="cmd+shift+l" onPress={toggleLights} />