Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/kmcaster.git
.idea/workspace.xml
<component name="ChangeListManager">
<list default="true" id="be1819c5-28d3-4984-9634-0b266734e13c" name="Default Changelist" comment="">
- <change afterPath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/listeners/Modifier.java" afterDir="false" />
- <change afterPath="$PROJECT_DIR$/src/main/resources/images/mouse/1-3.svg" afterDir="false" />
+ <change afterPath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/listeners/Key.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/AppImage.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/AppImage.java" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/EventFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/EventFrame.java" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/KmCaster.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/KmCaster.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/listeners/KeyboardListener.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/listeners/KeyboardListener.java" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/listeners/MouseListener.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/listeners/MouseListener.java" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/resources/images/mouse/0.svg" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/images/mouse/0.svg" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/resources/images/mouse/1.svg" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/images/mouse/1.svg" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/resources/images/mouse/2.svg" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/images/mouse/2.svg" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/resources/images/mouse/3.svg" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/images/mouse/3.svg" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/main/resources/images/mouse/all.svg" beforeDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/listeners/Modifier.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/com/whitemagicsoftware/kmcaster/listeners/KeyboardModifier.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="RECENT_TEMPLATES">
<list>
- <option value="Enum" />
<option value="Class" />
+ <option value="Enum" />
</list>
</option>
</state>
<state x="707" y="657" width="431" height="302" key="#com.intellij.refactoring.move.moveInner.MoveInnerDialog/0.28.2560.1529@0.28.2560.1529" timestamp="1594953392347" />
- <state x="567" y="28" width="711" height="1526" key="#com.intellij.refactoring.rename.AutomaticRenamingDialog" timestamp="1594858565314">
+ <state x="567" y="28" width="711" height="1526" key="#com.intellij.refactoring.rename.AutomaticRenamingDialog" timestamp="1594954562308">
<screen x="0" y="28" width="2560" height="1529" />
</state>
- <state x="567" y="28" width="711" height="1526" key="#com.intellij.refactoring.rename.AutomaticRenamingDialog/0.28.2560.1529@0.28.2560.1529" timestamp="1594858565314" />
+ <state x="567" y="28" width="711" height="1526" key="#com.intellij.refactoring.rename.AutomaticRenamingDialog/0.28.2560.1529@0.28.2560.1529" timestamp="1594954562308" />
<state x="659" y="559" width="526" height="497" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1594880960290">
<screen x="0" y="28" width="2560" height="1529" />
</state>
<state x="659" y="559" width="526" height="497" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.28.2560.1529@0.28.2560.1529" timestamp="1594880960290" />
<state x="710" y="704" width="425" height="207" key="DetectedRootsChooserDialog" timestamp="1594872764235">
<screen x="0" y="28" width="2560" height="1529" />
</state>
<state x="710" y="704" width="425" height="207" key="DetectedRootsChooserDialog/0.28.2560.1529@0.28.2560.1529" timestamp="1594872764235" />
- <state width="1479" height="330" key="GridCell.Tab.0.bottom" timestamp="1594954347951">
+ <state width="1479" height="330" key="GridCell.Tab.0.bottom" timestamp="1594955521867">
<screen x="0" y="28" width="2560" height="1529" />
</state>
- <state width="1479" height="330" key="GridCell.Tab.0.bottom/0.28.2560.1529@0.28.2560.1529" timestamp="1594954347951" />
- <state width="1479" height="330" key="GridCell.Tab.0.center" timestamp="1594954347950">
+ <state width="1479" height="330" key="GridCell.Tab.0.bottom/0.28.2560.1529@0.28.2560.1529" timestamp="1594955521867" />
+ <state width="1479" height="330" key="GridCell.Tab.0.center" timestamp="1594955521866">
<screen x="0" y="28" width="2560" height="1529" />
</state>
- <state width="1479" height="330" key="GridCell.Tab.0.center/0.28.2560.1529@0.28.2560.1529" timestamp="1594954347950" />
- <state width="1479" height="330" key="GridCell.Tab.0.left" timestamp="1594954347950">
+ <state width="1479" height="330" key="GridCell.Tab.0.center/0.28.2560.1529@0.28.2560.1529" timestamp="1594955521866" />
+ <state width="1479" height="330" key="GridCell.Tab.0.left" timestamp="1594955521866">
<screen x="0" y="28" width="2560" height="1529" />
</state>
- <state width="1479" height="330" key="GridCell.Tab.0.left/0.28.2560.1529@0.28.2560.1529" timestamp="1594954347950" />
- <state width="1479" height="330" key="GridCell.Tab.0.right" timestamp="1594954347951">
+ <state width="1479" height="330" key="GridCell.Tab.0.left/0.28.2560.1529@0.28.2560.1529" timestamp="1594955521866" />
+ <state width="1479" height="330" key="GridCell.Tab.0.right" timestamp="1594955521867">
<screen x="0" y="28" width="2560" height="1529" />
</state>
- <state width="1479" height="330" key="GridCell.Tab.0.right/0.28.2560.1529@0.28.2560.1529" timestamp="1594954347951" />
+ <state width="1479" height="330" key="GridCell.Tab.0.right/0.28.2560.1529@0.28.2560.1529" timestamp="1594955521867" />
<state width="1479" height="406" key="GridCell.Tab.1.bottom" timestamp="1594948352434">
<screen x="0" y="28" width="2560" height="1529" />
</state>
<state width="761" height="601" key="XDebugger.FullValuePopup/0.28.2560.1529@0.28.2560.1529" timestamp="1594940367498" />
- <state x="265" y="308" width="1323" height="1003" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1594881438574">
+ <state x="1068" y="347" width="1323" height="1003" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1594955523088">
<screen x="0" y="28" width="2560" height="1529" />
</state>
- <state x="265" y="308" width="1323" height="1003" key="com.intellij.history.integration.ui.views.FileHistoryDialog/0.28.2560.1529@0.28.2560.1529" timestamp="1594881438573" />
+ <state x="1068" y="347" width="1323" height="1003" key="com.intellij.history.integration.ui.views.FileHistoryDialog/0.28.2560.1529@0.28.2560.1529" timestamp="1594955523088" />
<state x="840" y="410" width="564" height="770" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser" timestamp="1594946566725">
<screen x="0" y="28" width="2560" height="1529" />
</state>
<state x="840" y="410" width="564" height="770" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/0.28.2560.1529@0.28.2560.1529" timestamp="1594946566725" />
<state x="833" y="545" width="586" height="502" key="find.popup" timestamp="1594949350582">
<screen x="0" y="28" width="2560" height="1529" />
</state>
<state x="833" y="545" width="586" height="502" key="find.popup/0.28.2560.1529@0.28.2560.1529" timestamp="1594949350582" />
- <state x="589" y="382" key="run.anything.popup" timestamp="1594881668952">
+ <state x="589" y="382" width="672" height="677" key="run.anything.popup" timestamp="1594954728874">
<screen x="0" y="28" width="2560" height="1529" />
</state>
- <state x="589" y="382" key="run.anything.popup/0.28.2560.1529@0.28.2560.1529" timestamp="1594881668952" />
- <state x="589" y="477" width="672" height="678" key="search.everywhere.popup" timestamp="1594880500645">
+ <state x="589" y="382" width="672" height="677" key="run.anything.popup/0.28.2560.1529@0.28.2560.1529" timestamp="1594954728874" />
+ <state x="589" y="477" width="672" height="678" key="search.everywhere.popup" timestamp="1594954743947">
<screen x="0" y="28" width="2560" height="1529" />
</state>
- <state x="589" y="477" width="672" height="678" key="search.everywhere.popup/0.28.2560.1529@0.28.2560.1529" timestamp="1594880500645" />
+ <state x="589" y="477" width="672" height="678" key="search.everywhere.popup/0.28.2560.1529@0.28.2560.1529" timestamp="1594954743947" />
</component>
</project>
src/main/com/whitemagicsoftware/kmcaster/listeners/Key.java
+/*
+ * Copyright 2020 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;
+
+/**
+ * Used for compile-time binding between change listeners and keyboard
+ * events.
+ */
+public enum Key {
+ KEY_ALT( "alt" ),
+ KEY_CTRL( "ctrl" ),
+ KEY_SHIFT( "shift" ),
+ KEY_REGULAR( "regular" );
+
+ private final String mName;
+
+ Key( final String name ) {
+ mName = name;
+ }
+
+ public boolean isName( final String name ) {
+ return mName.equalsIgnoreCase( name );
+ }
+
+ @Override
+ public String toString() {
+ return mName;
+ }
+}
src/main/com/whitemagicsoftware/kmcaster/listeners/KeyboardListener.java
import java.util.Map;
+import static com.whitemagicsoftware.kmcaster.listeners.Key.*;
import static java.util.Map.entry;
import static org.jnativehook.NativeInputEvent.*;
import static org.jnativehook.keyboard.NativeKeyEvent.getKeyText;
public class KeyboardListener implements NativeKeyListener {
- public final static String KEY_NAME_REGULAR = "regular";
-
- private final List<Modifier> mModifiers = List.of(
- new Modifier( "alt", ALT_MASK ),
- new Modifier( "ctrl", CTRL_MASK ),
- new Modifier( "shift", SHIFT_MASK )
+ private final List<KeyboardModifier> mModifiers = List.of(
+ new KeyboardModifier( KEY_ALT, ALT_MASK ),
+ new KeyboardModifier( KEY_CTRL, CTRL_MASK ),
+ new KeyboardModifier( KEY_SHIFT, SHIFT_MASK )
);
public void nativeKeyPressed( final NativeKeyEvent e ) {
final String regularHeld = getDisplayText( e );
+ boolean isRegular = true;
+ // The key is regular iff its name does not match any modifier name.
for( final var modifier : mModifiers ) {
- // If it's not a modifier key, broadcast the regular value.
- if( modifier.isName( regularHeld.toLowerCase() ) ) {
- tryFire( KEY_NAME_REGULAR, mRegularHeld, regularHeld );
- mRegularHeld = regularHeld;
- }
+ isRegular &= modifier.isKeyName( regularHeld );
+ }
+
+ // If it's not a modifier key, broadcast the regular value.
+ if( isRegular ) {
+ tryFire( KEY_REGULAR.toString(), mRegularHeld, regularHeld );
+ mRegularHeld = regularHeld;
}
src/main/com/whitemagicsoftware/kmcaster/listeners/KeyboardModifier.java
+/*
+ * Copyright 2020 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 org.jnativehook.keyboard.NativeKeyEvent;
+
+/**
+ * Responsible for tracking the state of modifier keys.
+ */
+class KeyboardModifier {
+ private boolean mHeld;
+ private final int mMask;
+ private final Key mKey;
+
+ KeyboardModifier( final Key key, final int mask ) {
+ assert key != null;
+
+ mKey = key;
+ mMask = mask;
+ }
+
+ public boolean isKeyName( final String key ) {
+ return mKey.isName( key );
+ }
+
+ public boolean isHeld() {
+ return mHeld;
+ }
+
+ public void setHeld( final boolean held ) {
+ mHeld = held;
+ }
+
+ /**
+ * Answers whether the given {@link NativeKeyEvent} modifiers are set to
+ * include the modifiers defined by this instance.
+ *
+ * @param e The event that has modifiers to check.
+ * @return {@code true} This modifier matches the given event's modifiers.
+ */
+ public boolean matches( final NativeKeyEvent e ) {
+ return (e.getModifiers() & mMask) != 0;
+ }
+
+ public String toString() {
+ return mKey.toString();
+ }
+}
src/main/com/whitemagicsoftware/kmcaster/listeners/Modifier.java
-/*
- * Copyright 2020 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 org.jnativehook.keyboard.NativeKeyEvent;
-
-import javax.swing.event.ChangeListener;
-
-/**
- * Responsible for tracking the state of modifier keys.
- */
-class Modifier {
- private boolean mHeld;
- private final int mMask;
- private final String mName;
-
- Modifier( final String name, final int mask ) {
- assert name != null;
-
- mName = name.toLowerCase();
- mMask = mask;
- }
-
- public boolean isName( final String name ) {
- return mName.equals( name );
- }
-
- public boolean isHeld() {
- return mHeld;
- }
-
- public void setHeld( final boolean held ) {
- mHeld = held;
- }
-
- /**
- * Answers whether the given {@link NativeKeyEvent} modifiers are set to
- * include the modifiers defined by this instance.
- *
- * @param e The event that has modifiers to check.
- * @return {@code true} This modifier matches the given event's modifiers.
- */
- public boolean matches( final NativeKeyEvent e ) {
- return (e.getModifiers() & mMask) != 0;
- }
-
- /**
- * Returns a unique identifier for this modifier that can be used by
- * a {@link ChangeListener}.
- *
- * @return The modifier key name, in lowercase.
- */
- @Override
- public String toString() {
- return mName;
- }
-}

Fix modifier press logic

Author DaveJarvis <email>
Date 2020-07-16 20:13:40 GMT-0700
Commit 7d04ecf9977afb6ed7ddc76d63b1e8b89b1a1b2c
Parent 13d8303
Delta 160 lines added, 121 lines removed, 39-line increase