import { toRefs , reactive , Ref } from '@vue/composition-api' ; import hotkeys from 'hotkeys-js' ; import keycode from 'keycode' ; import AppScope from '@/scopes/app' ; import { MalVal , getName } from '@/mal/types' ; let state ; hotkeys ( '*' , { keyup : true , keydown : true } , ( e ) => { if ( ! state ) { return ; } let code = keycode ( e ) ; if ( code . includes ( 'command' ) ) { code = 'ctrl' ; } if ( code in state ) { state [ code ] . value = e . type === 'keydown' ; } } ) ; export default function useKeyboardState ( ) { if ( ! state ) { state = toRefs ( reactive ( { shift : false , alt : false , ctrl : false , } ) ) ; } AppScope . def ( 'modifier-pressed?' , ( ... keys ) => { for ( const key of keys ) { const code = getName ( key ) ; if ( ! state [ code ] || ! state [ code ] . value ) { return false ; } } return true ; } ) ; return state ; }