Dave Jarvis' Repositories

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

Add debug listener, change command-line options

Author DaveJarvis <email>
Date 2023-01-08 13:52:23 GMT-0800
Commit f6c8797df640ffe1690641ab938d72fedd03c8fe
Parent 57ef07d
Delta 127 lines added, 30 lines removed, 97-line increase
src/main/java/com/whitemagicsoftware/kmcaster/KmCaster.java
import com.github.kwhat.jnativehook.GlobalScreen;
import com.github.kwhat.jnativehook.NativeHookException;
+import com.whitemagicsoftware.kmcaster.listeners.DebugListener;
import com.whitemagicsoftware.kmcaster.listeners.FrameDragListener;
import com.whitemagicsoftware.kmcaster.listeners.KeyboardListener;
initMouseListener( eventHandler );
initKeyboardListener( eventHandler );
+ initDebugListener();
}
keyboardListener.addPropertyChangeListener( listener );
keyboardListener.initModifiers();
+ }
+
+ private void initDebugListener() {
+ if( isDebugEnabled() ) {
+ final DebugListener debugListener = new DebugListener();
+ addNativeKeyListener( debugListener );
+ }
}
private int getGapVertical() {
return getUserSettings().getGapVertical();
+ }
+
+ private boolean isDebugEnabled() {
+ return getUserSettings().isDebugEnabled();
}
src/main/java/com/whitemagicsoftware/kmcaster/Settings.java
/**
- * Application height in pixels. Images are scaled to this height, maintaining
- * aspect ratio. The height constrains the width, so as long as the width
- * is large enough, the application's window will adjust to fit.
+ * Debugging for keystrokes.
*/
@CommandLine.Option(
- names = {"-d", "--dimension"},
+ names = {"-d", "--debug"},
description =
- "Application height (${DEFAULT-VALUE} pixels)",
- paramLabel = "pixels",
- defaultValue = "100"
+ "Enable debugging (${DEFAULT-VALUE})",
+ paramLabel = "Boolean",
+ defaultValue = "false"
)
- private int mHeight = 100;
+ private boolean mDebug = false;
/**
/**
- * Milliseconds to wait before releasing (clearing) any modifier key.
+ * Amount of padding above and below the frame.
*/
@CommandLine.Option(
- names = {"-m", "--delay-modifier"},
+ names = {"--gap-horizontal"},
description =
- "Modifier key release delay (${DEFAULT-VALUE} milliseconds)",
- paramLabel = "ms",
- defaultValue = "150"
+ "Amount of padding above and below frame (${DEFAULT-VALUE} pixels)",
+ paramLabel = "pixels",
+ defaultValue = "5"
)
- private int mDelayKeyModifier = 150;
+ private int mGapHorizontal = 5;
+
+ /**
+ * Amount of padding between items in the frame.
+ */
+ @CommandLine.Option(
+ names = {"--gap-vertical"},
+ description =
+ "Amount of padding between switches (${DEFAULT-VALUE} pixels)",
+ paramLabel = "pixels",
+ defaultValue = "5"
+ )
+ private int mGapVertical = 5;
/**
/**
- * Milliseconds to wait before releasing (clearing) a mouse scroll event.
+ * Milliseconds to wait before releasing (clearing) any modifier key.
*/
@CommandLine.Option(
- names = {"-s", "--delay-scroll"},
+ names = {"-m", "--delay-modifier"},
description =
- "Mouse scroll release delay (${DEFAULT-VALUE} milliseconds)",
+ "Modifier key release delay (${DEFAULT-VALUE} milliseconds)",
paramLabel = "ms",
- defaultValue = "300"
+ defaultValue = "150"
)
- private int mDelayMouseScroll = 300;
+ private int mDelayKeyModifier = 150;
/**
- * Amount of padding above and below the frame.
+ * Application height in pixels. Images are scaled to this height, maintaining
+ * aspect ratio. The height constrains the width, so as long as the width
+ * is large enough, the application's window will adjust to fit.
*/
@CommandLine.Option(
- names = {"--gap-horizontal"},
+ names = {"-p", "--proportion"},
description =
- "Amount of padding above and below frame (${DEFAULT-VALUE} pixels)",
+ "Application height (${DEFAULT-VALUE} pixels)",
paramLabel = "pixels",
- defaultValue = "5"
+ defaultValue = "100"
)
- private int mGapHorizontal = 5;
+ private int mHeight = 100;
/**
- * Amount of padding between items in the frame.
+ * Milliseconds to wait before releasing (clearing) a mouse scroll event.
*/
@CommandLine.Option(
- names = {"--gap-vertical"},
+ names = {"-s", "--delay-scroll"},
description =
- "Amount of padding between switches (${DEFAULT-VALUE} pixels)",
- paramLabel = "pixels",
- defaultValue = "5"
+ "Mouse scroll release delay (${DEFAULT-VALUE} milliseconds)",
+ paramLabel = "ms",
+ defaultValue = "300"
)
- private int mGapVertical = 5;
+ private int mDelayMouseScroll = 300;
public Settings( final KmCaster kmCaster ) {
public String getBackgroundColour() {
return mBackgroundColour;
+ }
+
+ public boolean isDebugEnabled() {
+ return mDebug;
}
}
src/main/java/com/whitemagicsoftware/kmcaster/listeners/DebugListener.java
+/*
+ * Copyright 2023 White Magic Software, Ltd.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.whitemagicsoftware.kmcaster.listeners;
+
+import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
+import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Displays key event details when debug mode is enabled.
+ */
+public final class DebugListener implements NativeKeyListener {
+
+ private final Map<Integer, String> mPreviousActions = new HashMap<>();
+
+ @Override
+ public void nativeKeyTyped( final NativeKeyEvent event ) {
+ log( event );
+ }
+
+ @Override
+ public void nativeKeyPressed( final NativeKeyEvent event ) {
+ log( event );
+ }
+
+ @Override
+ public void nativeKeyReleased( final NativeKeyEvent event ) {
+ log( event );
+ }
+
+ private void log( final NativeKeyEvent event ) {
+ assert event != null;
+
+ final var param = event.paramString();
+ final var id = event.getID();
+ if( mPreviousActions.getOrDefault( id, "" ).equals( param ) ) {
+ mPreviousActions.put( id, param );
+ System.out.println( param );
+ }
+ }
+}