From: Kevin Lamonte Date: Thu, 31 Oct 2019 02:08:21 +0000 (-0500) Subject: Read keyboard modifiers with mouse events X-Git-Tag: fanfix-3.0.1^2~4^2~41 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=6e9daafbcbfa145fa1f7c9ca839f2a05ccf024c2;p=fanfix.git Read keyboard modifiers with mouse events --- diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index 22a2479..4fb3bd6 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -1177,7 +1177,8 @@ public class TApplication implements Runnable { mouse.getAbsoluteX(), mouse.getAbsoluteY(), mouse.isMouse1(), mouse.isMouse2(), mouse.isMouse3(), - mouse.isMouseWheelUp(), mouse.isMouseWheelDown()); + mouse.isMouseWheelUp(), mouse.isMouseWheelDown(), + mouse.isAlt(), mouse.isCtrl(), mouse.isShift()); } else { // The first click of a potential double-click. @@ -1366,7 +1367,8 @@ public class TApplication implements Runnable { mouse.getAbsoluteX(), mouse.getAbsoluteY(), mouse.isMouse1(), mouse.isMouse2(), mouse.isMouse3(), - mouse.isMouseWheelUp(), mouse.isMouseWheelDown()); + mouse.isMouseWheelUp(), mouse.isMouseWheelDown(), + mouse.isAlt(), mouse.isCtrl(), mouse.isShift()); } else { // The first click of a potential double-click. diff --git a/src/jexer/backend/ECMA48Terminal.java b/src/jexer/backend/ECMA48Terminal.java index 2ce6378..5b5db6b 100644 --- a/src/jexer/backend/ECMA48Terminal.java +++ b/src/jexer/backend/ECMA48Terminal.java @@ -2238,10 +2238,13 @@ public class ECMA48Terminal extends LogicalScreen boolean eventMouse3 = false; boolean eventMouseWheelUp = false; boolean eventMouseWheelDown = false; + boolean eventAlt = false; + boolean eventCtrl = false; + boolean eventShift = false; // System.err.printf("buttons: %04x\r\n", buttons); - switch (buttons) { + switch (buttons & 0xE3) { case 0: eventMouse1 = true; mouse1 = true; @@ -2323,9 +2326,21 @@ public class ECMA48Terminal extends LogicalScreen eventType = TMouseEvent.Type.MOUSE_MOTION; break; } + + if ((buttons & 0x04) != 0) { + eventShift = true; + } + if ((buttons & 0x08) != 0) { + eventAlt = true; + } + if ((buttons & 0x10) != 0) { + eventCtrl = true; + } + return new TMouseEvent(eventType, x, y, x, y, eventMouse1, eventMouse2, eventMouse3, - eventMouseWheelUp, eventMouseWheelDown); + eventMouseWheelUp, eventMouseWheelDown, + eventAlt, eventCtrl, eventShift); } /** @@ -2360,12 +2375,15 @@ public class ECMA48Terminal extends LogicalScreen boolean eventMouse3 = false; boolean eventMouseWheelUp = false; boolean eventMouseWheelDown = false; + boolean eventAlt = false; + boolean eventCtrl = false; + boolean eventShift = false; if (release) { eventType = TMouseEvent.Type.MOUSE_UP; } - switch (buttons) { + switch (buttons & 0xE3) { case 0: eventMouse1 = true; break; @@ -2422,9 +2440,21 @@ public class ECMA48Terminal extends LogicalScreen // Unknown, bail out return null; } + + if ((buttons & 0x04) != 0) { + eventShift = true; + } + if ((buttons & 0x08) != 0) { + eventAlt = true; + } + if ((buttons & 0x10) != 0) { + eventCtrl = true; + } + return new TMouseEvent(eventType, x, y, x, y, eventMouse1, eventMouse2, eventMouse3, - eventMouseWheelUp, eventMouseWheelDown); + eventMouseWheelUp, eventMouseWheelDown, + eventAlt, eventCtrl, eventShift); } /** diff --git a/src/jexer/backend/SwingTerminal.java b/src/jexer/backend/SwingTerminal.java index f0ba355..c2b335f 100644 --- a/src/jexer/backend/SwingTerminal.java +++ b/src/jexer/backend/SwingTerminal.java @@ -2101,6 +2101,10 @@ public class SwingTerminal extends LogicalScreen boolean eventMouse1 = false; boolean eventMouse2 = false; boolean eventMouse3 = false; + boolean eventAlt = false; + boolean eventCtrl = false; + boolean eventShift = false; + if ((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) { eventMouse1 = true; } @@ -2110,6 +2114,16 @@ public class SwingTerminal extends LogicalScreen if ((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) { eventMouse3 = true; } + if ((modifiers & MouseEvent.ALT_DOWN_MASK) != 0) { + eventAlt = true; + } + if ((modifiers & MouseEvent.CTRL_DOWN_MASK) != 0) { + eventCtrl = true; + } + if ((modifiers & MouseEvent.SHIFT_DOWN_MASK) != 0) { + eventShift = true; + } + mouse1 = eventMouse1; mouse2 = eventMouse2; mouse3 = eventMouse3; @@ -2117,7 +2131,8 @@ public class SwingTerminal extends LogicalScreen int y = textRow(mouse.getY()); TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_MOTION, - x, y, x, y, mouse1, mouse2, mouse3, false, false); + x, y, x, y, mouse1, mouse2, mouse3, false, false, + eventAlt, eventCtrl, eventShift); synchronized (eventQueue) { eventQueue.add(mouseEvent); @@ -2145,8 +2160,24 @@ public class SwingTerminal extends LogicalScreen oldMouseX = x; oldMouseY = y; + boolean eventAlt = false; + boolean eventCtrl = false; + boolean eventShift = false; + + int modifiers = mouse.getModifiersEx(); + if ((modifiers & MouseEvent.ALT_DOWN_MASK) != 0) { + eventAlt = true; + } + if ((modifiers & MouseEvent.CTRL_DOWN_MASK) != 0) { + eventCtrl = true; + } + if ((modifiers & MouseEvent.SHIFT_DOWN_MASK) != 0) { + eventShift = true; + } + TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_MOTION, - x, y, x, y, mouse1, mouse2, mouse3, false, false); + x, y, x, y, mouse1, mouse2, mouse3, false, false, + eventAlt, eventCtrl, eventShift); synchronized (eventQueue) { eventQueue.add(mouseEvent); @@ -2200,6 +2231,10 @@ public class SwingTerminal extends LogicalScreen boolean eventMouse1 = false; boolean eventMouse2 = false; boolean eventMouse3 = false; + boolean eventAlt = false; + boolean eventCtrl = false; + boolean eventShift = false; + if ((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) { eventMouse1 = true; } @@ -2209,6 +2244,16 @@ public class SwingTerminal extends LogicalScreen if ((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) { eventMouse3 = true; } + if ((modifiers & MouseEvent.ALT_DOWN_MASK) != 0) { + eventAlt = true; + } + if ((modifiers & MouseEvent.CTRL_DOWN_MASK) != 0) { + eventCtrl = true; + } + if ((modifiers & MouseEvent.SHIFT_DOWN_MASK) != 0) { + eventShift = true; + } + mouse1 = eventMouse1; mouse2 = eventMouse2; mouse3 = eventMouse3; @@ -2216,7 +2261,8 @@ public class SwingTerminal extends LogicalScreen int y = textRow(mouse.getY()); TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_DOWN, - x, y, x, y, mouse1, mouse2, mouse3, false, false); + x, y, x, y, mouse1, mouse2, mouse3, false, false, + eventAlt, eventCtrl, eventShift); synchronized (eventQueue) { eventQueue.add(mouseEvent); @@ -2239,6 +2285,10 @@ public class SwingTerminal extends LogicalScreen boolean eventMouse1 = false; boolean eventMouse2 = false; boolean eventMouse3 = false; + boolean eventAlt = false; + boolean eventCtrl = false; + boolean eventShift = false; + if ((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) { eventMouse1 = true; } @@ -2248,6 +2298,16 @@ public class SwingTerminal extends LogicalScreen if ((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) { eventMouse3 = true; } + if ((modifiers & MouseEvent.ALT_DOWN_MASK) != 0) { + eventAlt = true; + } + if ((modifiers & MouseEvent.CTRL_DOWN_MASK) != 0) { + eventCtrl = true; + } + if ((modifiers & MouseEvent.SHIFT_DOWN_MASK) != 0) { + eventShift = true; + } + if (mouse1) { mouse1 = false; eventMouse1 = true; @@ -2264,7 +2324,8 @@ public class SwingTerminal extends LogicalScreen int y = textRow(mouse.getY()); TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_UP, - x, y, x, y, eventMouse1, eventMouse2, eventMouse3, false, false); + x, y, x, y, eventMouse1, eventMouse2, eventMouse3, false, false, + eventAlt, eventCtrl, eventShift); synchronized (eventQueue) { eventQueue.add(mouseEvent); @@ -2293,6 +2354,10 @@ public class SwingTerminal extends LogicalScreen boolean eventMouse3 = false; boolean mouseWheelUp = false; boolean mouseWheelDown = false; + boolean eventAlt = false; + boolean eventCtrl = false; + boolean eventShift = false; + if ((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) { eventMouse1 = true; } @@ -2302,6 +2367,16 @@ public class SwingTerminal extends LogicalScreen if ((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) { eventMouse3 = true; } + if ((modifiers & MouseEvent.ALT_DOWN_MASK) != 0) { + eventAlt = true; + } + if ((modifiers & MouseEvent.CTRL_DOWN_MASK) != 0) { + eventCtrl = true; + } + if ((modifiers & MouseEvent.SHIFT_DOWN_MASK) != 0) { + eventShift = true; + } + mouse1 = eventMouse1; mouse2 = eventMouse2; mouse3 = eventMouse3; @@ -2315,7 +2390,8 @@ public class SwingTerminal extends LogicalScreen } TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_DOWN, - x, y, x, y, mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown); + x, y, x, y, mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown, + eventAlt, eventCtrl, eventShift); synchronized (eventQueue) { eventQueue.add(mouseEvent); diff --git a/src/jexer/event/TMouseEvent.java b/src/jexer/event/TMouseEvent.java index 496d8bc..e529898 100644 --- a/src/jexer/event/TMouseEvent.java +++ b/src/jexer/event/TMouseEvent.java @@ -118,6 +118,21 @@ public class TMouseEvent extends TInputEvent { */ private boolean mouseWheelDown; + /** + * Keyboard modifier ALT. + */ + private boolean alt; + + /** + * Keyboard modifier CTRL. + */ + private boolean ctrl; + + /** + * Keyboard modifier SHIFT. + */ + private boolean shift; + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -135,11 +150,15 @@ public class TMouseEvent extends TInputEvent { * @param mouse3 if true, middle button is down * @param mouseWheelUp if true, mouse wheel (button 4) is down * @param mouseWheelDown if true, mouse wheel (button 5) is down + * @param alt if true, ALT was pressed with this mouse event + * @param ctrl if true, CTRL was pressed with this mouse event + * @param shift if true, SHIFT was pressed with this mouse event */ public TMouseEvent(final Type type, final int x, final int y, final int absoluteX, final int absoluteY, final boolean mouse1, final boolean mouse2, final boolean mouse3, - final boolean mouseWheelUp, final boolean mouseWheelDown) { + final boolean mouseWheelUp, final boolean mouseWheelDown, + final boolean alt, final boolean ctrl, final boolean shift) { this.type = type; this.x = x; @@ -151,6 +170,9 @@ public class TMouseEvent extends TInputEvent { this.mouse3 = mouse3; this.mouseWheelUp = mouseWheelUp; this.mouseWheelDown = mouseWheelDown; + this.alt = alt; + this.ctrl = ctrl; + this.shift = shift; } // ------------------------------------------------------------------------ @@ -289,6 +311,33 @@ public class TMouseEvent extends TInputEvent { return mouseWheelDown; } + /** + * Getter for ALT. + * + * @return alt value + */ + public boolean isAlt() { + return alt; + } + + /** + * Getter for CTRL. + * + * @return ctrl value + */ + public boolean isCtrl() { + return ctrl; + } + + /** + * Getter for SHIFT. + * + * @return shift value + */ + public boolean isShift() { + return shift; + } + /** * Create a duplicate instance. * @@ -296,7 +345,9 @@ public class TMouseEvent extends TInputEvent { */ public TMouseEvent dup() { TMouseEvent mouse = new TMouseEvent(type, x, y, absoluteX, absoluteY, - mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown); + mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown, + alt, ctrl, shift); + return mouse; } @@ -307,7 +358,7 @@ public class TMouseEvent extends TInputEvent { */ @Override public String toString() { - return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s", + return String.format("Mouse: %s x %d y %d absoluteX %d absoluteY %d 1 %s 2 %s 3 %s DOWN %s UP %s ALT %s CTRL %s SHIFT %s", type, x, y, absoluteX, absoluteY, @@ -315,7 +366,8 @@ public class TMouseEvent extends TInputEvent { mouse2, mouse3, mouseWheelUp, - mouseWheelDown); + mouseWheelDown, + alt, ctrl, shift); } }