Optional
validEmulate pressing/releasing keys.
// press and release a
emulator.fire("KeyA")
// hold A down
emulator.fire("KeyA+")
// release A
emulator.fire("KeyA-")
// press Ctrl+A
emulator.fire("Ctrl+ KeyA Ctrl-")
// to truly simulate pressing native modifiers, pass all modifiers pressed as an array
emulator.fire("Ctrl+ KeyA Ctrl-", ["ControlLeft"])
// emulate a modifier state change out of focus
// e.g. user focuses out, holds control+A, and focuses back
// only KeyA would fire
emulator.fire("KeyA+", ["ControlLeft"])
// they release both in focus
emulater.fire("KeyA- Ctrl-")
// to simulate them releasing out of focus again you will have to add a delay since no events would fire
delay(1000)
Keys should be a KeyboardEvent.code (though this is not validated) seperated by one or more whitespace characters*. For buttons 0-5
can be used. For wheel events, you can pass wheelUp/Down
to set the deltaY respectively which is how the manager gets the direction.
+
and -
are used to indicate keydown and keyup respectively (except for wheel events*). This can seem confusing but think of the signs as adding/removing from the set of currently held keys. If no +/-
is given, both are fired.
There is no need to handle toggle keys in any special way. You should fire the root code normally (e.g. emulator.fire("Capslock")
or emulator.fire("Capslock+ Capslock-")
)
* Multiple whitespace characters have no real meaning, but in tests usually I use them to more easily delimite chords.
** Wheel events do not have keyup/keydown so passing wheelUp+/-
will incorrectly create a keyboard event.
Note: While the emulator is aware of correct mouse/wheel names, it does not check key names are valid.
A simple key emulator for testing purposes. Should be hooked up to a manager class as if it was an element: