Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/kmcaster.git

Add delay for mouse button release

Author DaveJarvis <email>
Date 2020-07-31 20:29:51 GMT-0700
Commit 998888b2ec56488390ac53a0391ae088fdb9cd95
Parent 36c2d10
src/main/com/whitemagicsoftware/kmcaster/EventHandler.java
hwSwitch, hwState, switchValue );
- if( hwSwitch.isKeyboard() ) {
- final var timer = getTimer( hwSwitch );
+ final var timer = getTimer( hwSwitch );
+ if( hwSwitch.isKeyboard() ) {
if( hwState == SWITCH_RELEASED ) {
timer.addActionListener(
}
else {
- updateSwitchState( switchState );
+ if( hwState == SWITCH_RELEASED ) {
+ timer.addActionListener(
+ ( event ) -> updateSwitchState( switchState )
+ );
+ }
+ else {
+ timer.stop();
+ updateSwitchState( switchState );
+ }
}
}
src/main/com/whitemagicsoftware/kmcaster/HardwareImages.java
final var stateOn = state( key, SWITCH_PRESSED );
final var stateOff = state( key, SWITCH_RELEASED );
- final var imageDn = mouseImage( key.toString() );
- mouseStates.put( stateOn, imageDn.getKey() );
- mouseStates.put( stateOff, mouseReleased.getKey() );
- mSwitches.put( key, mouseStates );
+
+ try {
+ final var imageDn = mouseImage( key.toString() );
+ mouseStates.put( stateOn, imageDn.getKey() );
+ mouseStates.put( stateOff, mouseReleased.getKey() );
+ mSwitches.put( key, mouseStates );
+ }
+ catch( final Exception e ) {
+ // Not all mouse buttons map to images.
+ }
}
Delta 21 lines added, 7 lines removed, 14-line increase