Skip to content

Commit 8a79cd1

Browse files
committed
Mouse event fix for right-button and shift drag
1 parent efaa9f8 commit 8a79cd1

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

sources/net.sf.j2s.java.core/src/swingjs/JSMouse.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public boolean processEvent(int id, int x, int y, int modifiers, long time, Obje
6969
return keyAction(id, jqevent, time);
7070
}
7171
if (id != MouseEvent.MOUSE_WHEEL
72-
&& id != MouseEvent.MOUSE_MOVED
73-
&& id != MouseEvent.MOUSE_DRAGGED)
72+
&& id != MouseEvent.MOUSE_MOVED)
7473
modifiers = applyLeftMouse(modifiers);
7574
switch (id) {
7675
case MouseEvent.MOUSE_WHEEL:

sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// j2sApplet.js BH = Bob Hanson hansonr@stolaf.edu
22

3+
// BH 2023.12.13 fixes RIGHT-DRAG and SHIFT-LEFT-DRAG modifier
34
// BH 2023.12.07 fixes mouseUp on body causing (ignorable) error
45
// BH 2023.11.06 adds css touch-action none
56
// BH 2023.11.01 adds pointerup, pointerdown, and pointermove to J2S.setMouse
@@ -1686,26 +1687,6 @@ if (database == "_" && J2S._serverUrl.indexOf("//your.server.here/") >= 0) {
16861687
return ignore;
16871688
};
16881689

1689-
var getKeyModifiers = function(ev) {
1690-
var modifiers = 0;
1691-
if (ev.shiftKey)
1692-
modifiers |= (1 << 0) | (1 << 6); // InputEvent.SHIFT_MASK +
1693-
// InputEvent.SHIFT_DOWN_MASK;
1694-
if (ev.ctrlKey)
1695-
modifiers |= (1 << 1) | (1 << 7); // InputEvent.CTRL_MASK +
1696-
// InputEvent.CTRL_DOWN_MASK;
1697-
if (ev.metaKey)
1698-
modifiers |= (1 << 2) | (1 << 8); // InputEvent.META_MASK +
1699-
// InputEvent.META_DOWN_MASK;
1700-
if (ev.altKey)
1701-
modifiers |= (1 << 3) | (1 << 9); // InputEvent.ALT_MASK +
1702-
// InputEvent.ALT_DOWN_MASK;
1703-
if (ev.altGraphKey)
1704-
modifiers |= (1 << 5) | (1 << 13); // InputEvent.ALT_GRAPH_MASK +
1705-
// InputEvent.ALT_GRAPH_DOWN_MASK;
1706-
return modifiers;
1707-
}
1708-
17091690
J2S.setKeyListener = function(who) {
17101691
J2S.$bind(who, 'keydown keypress keyup', function(ev) {
17111692
if (doIgnore(ev))
@@ -2178,7 +2159,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
21782159
// and also recognize a drag (503 + buttons pressed
21792160
var modifiers = 0;
21802161
if (id == 503) {
2181-
modifiers = ev.buttons << 10;
2162+
modifiers = (ev.buttons == 0 ? 0 : ev.buttons == 2 ? (1 << 12) : (1 << 10));
21822163
} else {
21832164
switch (ev.button) {
21842165
default:
@@ -2202,6 +2183,26 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
22022183
return modifiers | getKeyModifiers(ev);
22032184
}
22042185

2186+
var getKeyModifiers = function(ev) {
2187+
var modifiers = 0;
2188+
if (ev.shiftKey)
2189+
modifiers |= (1 << 0) | (1 << 6); // InputEvent.SHIFT_MASK +
2190+
// InputEvent.SHIFT_DOWN_MASK;
2191+
if (ev.ctrlKey)
2192+
modifiers |= (1 << 1) | (1 << 7); // InputEvent.CTRL_MASK +
2193+
// InputEvent.CTRL_DOWN_MASK;
2194+
if (ev.metaKey)
2195+
modifiers |= (1 << 2) | (1 << 8); // InputEvent.META_MASK +
2196+
// InputEvent.META_DOWN_MASK;
2197+
if (ev.altKey)
2198+
modifiers |= (1 << 3) | (1 << 9); // InputEvent.ALT_MASK +
2199+
// InputEvent.ALT_DOWN_MASK;
2200+
if (ev.altGraphKey)
2201+
modifiers |= (1 << 5) | (1 << 13); // InputEvent.ALT_GRAPH_MASK +
2202+
// InputEvent.ALT_GRAPH_DOWN_MASK;
2203+
return modifiers;
2204+
}
2205+
22052206
var getXY = function(who, ev, id) {
22062207
// id 0, 502, or 503 only
22072208
if (!who.applet._ready || J2S._touching && ev.type.indexOf("touch") < 0)

0 commit comments

Comments
 (0)