 : find-keyboard ( -- )
     GUID_SysKeyboard device-for-guid
     [ configure-keyboard ]
-    [ +keyboard-device+ set-global ] bi ;
+    [ +keyboard-device+ set-global ] bi
+    256 <byte-array> <keys-array> keyboard-state boa
+    +keyboard-state+ set-global ;
 
 : device-info ( device -- DIDEVICEIMAGEINFOW )
     "DIDEVICEINSTANCEW" <c-object>

    [ drop pov-neutral ]
    [ 2750 + 4500 /i pov-values nth ] if ;
: >buttons ( alien length -- array )
    memory>byte-array >keys ;

: (fill-if) ( controller-state DIJOYSTATE2 ? quot -- )
    [ drop ] compose [ 2drop ] if ; inline

    handle>> f 0 IDirectInputDevice8W::RunControlPanel ole32-error ;

M: dinput-game-input-backend read-keyboard
    +keyboard-device+ get
    [ +keyboard-state+ get [ keys>> underlying>> get-device-state ] keep ]
    [ ] [ f ] with-acquisition ;

dinput-game-input-backend game-input-backend set-global
