This commit is contained in:
20
public/src/composables/enter.ts
Normal file
20
public/src/composables/enter.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import {onMounted, onUnmounted} from "vue";
|
||||
|
||||
|
||||
export function useWindowEvent<K extends keyof WindowEventMap>(event: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined){
|
||||
onMounted(() => {
|
||||
window.addEventListener(event, listener, options as any)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener(event, listener)
|
||||
})
|
||||
}
|
||||
|
||||
export function onKeyPress(key: string, listener: () => void) {
|
||||
useWindowEvent("keydown", (event) => {
|
||||
if(event.key == key) {
|
||||
listener()
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user