Skip to content

Commit 1f0f898

Browse files
MGTK: Change MouseKeys to make dragging easier, support modifiers
Previously, in MouseKeys mode the Solid Apple key was used as the mouse button. This was easy to implement as it could be held down while other keys were used to perform drag operations. Unfortunately, this conflicted with the use of the key as a modifier for operations, so you could not perform a drag/drop while holding Solid Apple to force a copy (same volume) or move (other volume). This impacted automated testing, which uses MouseKeys extensively. This is now changed to be similar to how modern macOS works, albeit with different keys: * OA + SA + Space enters MouseKeys mode (no change) * Arrow keys move the mouse cursor (no change0 * Space now clicks the mouse button * Comma now presses and holds the mouse button (start a drag) * Period now releases the mouse button (end a drag) * Escape exits MouseKeys mode (no change)
1 parent a305cc2 commit 1f0f898

File tree

8 files changed

+111
-73
lines changed

8 files changed

+111
-73
lines changed

RELEASE-NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Project Page: https://github.com/a2stuff/a2d
1111
* Eliminate cursor flickering when mouse is moved.
1212
* Improve visibility of button flashing using VBL.
1313
* Adjust movement scaling in MouseKeys mode.
14+
* Change MouseKeys mode to make dragging easier and support modifiers:
15+
* Space clicks the mouse button
16+
* Comma presses and holds the mouse button
17+
* Period releases the mouse button
18+
* Solid Apple is now just a modifier as normal
1419

1520
### Launcher
1621

src/mgtk/MGTK.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,15 @@ Parameters:
440440

441441
## Mouse Keys
442442

443-
* To enter Mouse Keys mode, hold down both the Open-Apple key and the Solid-Apple (Option) key and then press the Space key. A confirmation sound will play.
444-
* Move the mouse cursor using the arrow keys. Use the Solid-Apple (or Option) key as the mouse button.
445-
* To exit Mouse Keys mode, press Escape. A confirmation sound will play.
443+
* To enter Mouse Keys mode, hold down both the Open-Apple key and the Solid-Apple (Option) key and then press <kbd>Space</kbd>. A confirmation sound will play.
444+
* While in Mouse Keys mode, use these keys:
445+
* <kbd>←</kbd> <kbd>↑</kbd> <kbd>→</kbd> <kbd>↓</kbd> (Arrow keys) move the mouse cursor
446+
* <kbd>Space</kbd> click the mouse button
447+
* <kbd>,</kbd> press and hold the mouse button
448+
* <kbd>.</kbd> release the mouse button
449+
* To exit Mouse Keys mode, press <kbd>Esc</kbd>. A confirmation sound will play.
450+
451+
> Earlier versions of the toolkit used different key sequences to enter, exit, and control the mouse.
446452
447453
## Concepts
448454

src/mgtk/mgtk.s

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9729,8 +9729,13 @@ saved_mouse_x: .word 0
97299729
saved_mouse_y: .byte 0
97309730

97319731
movement_cancel: .byte $00
9732+
9733+
;;; bit7 = current button state; bit6 = last button state
97329734
kbd_mouse_status: .byte $00
97339735

9736+
;;; bit7 = next button state to use (assuming no changes)
9737+
kbd_mouse_next_status: .byte $00
9738+
97349739
;;; ============================================================
97359740
;;; X = xlo, Y = xhi, A = y
97369741

@@ -9951,20 +9956,57 @@ restore_addr:
99519956
stashed_addr: .addr 0
99529957

99539958

9954-
.proc KbdMouseMousekeys
9955-
jsr ComputeModifiers ; C=_ A=____ __SO
9956-
ror a ; C=O A=____ ___S
9957-
ror a ; C=S A=O___ ____
9958-
ror kbd_mouse_status ; shift solid apple into bit 7 of kbd_mouse_status
9959-
lda kbd_mouse_status ; becomes mouse button
9960-
sta mouse_status
9961-
lda #0
9962-
sta input::modifiers
99639959

9960+
9961+
.proc KbdMouseMousekeys
99649962
jsr GetKey
9965-
jcs MousekeysInput
9963+
IF CC
9964+
jsr use_next_status
9965+
jmp PositionKbdMouse
9966+
END_IF
9967+
9968+
IF A = #CHAR_ESCAPE
9969+
jmp EndMouseKeys
9970+
END_IF
9971+
9972+
IF A = #' '
9973+
lda #%10 ; down, then stay up
9974+
bne new_status ; always
9975+
END_IF
9976+
9977+
IF A = #','
9978+
lda #%11 ; down, stay down
9979+
bne new_status ; always
9980+
END_IF
9981+
9982+
IF A = #'.'
9983+
lda #%00 ; up, stay up
9984+
beq new_status ; always
9985+
END_IF
9986+
9987+
pha
9988+
jsr use_next_status
9989+
pla
9990+
jmp MousekeysInput
99669991

9992+
new_status:
9993+
ror ; C = sticky next status
9994+
ror kbd_mouse_next_status
9995+
ror ; C = new current status
9996+
jsr update_status
99679997
jmp PositionKbdMouse
9998+
9999+
use_next_status:
10000+
lda kbd_mouse_next_status
10001+
rol
10002+
FALL_THROUGH_TO update_status
10003+
10004+
update_status:
10005+
;; C goes into bit7 as new button status
10006+
;; bit6 becomes "what was last button status?"
10007+
ror kbd_mouse_status
10008+
copy8 kbd_mouse_status, mouse_status
10009+
rts
996810010
.endproc ; KbdMouseMousekeys
996910011

997010012

@@ -9996,6 +10038,7 @@ stashed_addr: .addr 0
999610038
sta kbd_mouse_state
999710039
lda #0
999810040
sta kbd_mouse_status ; reset mouse button status
10041+
sta kbd_mouse_next_status
999910042
COPY_BYTES 3, cursor_pos, kbd_mouse_x
1000010043

1000110044
RETURN C=0
@@ -10257,11 +10300,8 @@ pos: jmp PositionKbdMouse
1025710300
kMouseKeysDeltaX = 8
1025810301
kMouseKeysDeltaY = 4
1025910302

10303+
;;; Used by both `kKeyboardMouseStateMouseKeys` and `kKeyboardMouseStateForced`
1026010304
.proc MousekeysInput
10261-
IF A = #CHAR_ESCAPE
10262-
jmp EndMouseKeys
10263-
END_IF
10264-
1026510305
IF A = #CHAR_UP
1026610306
lda #256-kMouseKeysDeltaY
1026710307
jmp KbdMouseAddToY

tests/lib/a2d.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,7 @@ function a2d.MouseKeysDoubleClick()
512512
end
513513

514514
function a2d.MouseKeysClick()
515-
a2d.MouseKeysButtonDown()
516-
emu.wait(1/60)
517-
a2d.MouseKeysButtonUp()
518-
emu.wait(1/60)
515+
apple2.SpaceKey()
519516
end
520517

521518
function a2d.MouseKeysOAClick()
@@ -551,11 +548,11 @@ function a2d.MouseKeysRight(n)
551548
end
552549

553550
function a2d.MouseKeysButtonDown()
554-
apple2.PressSA()
551+
apple2.Type(",")
555552
end
556553

557554
function a2d.MouseKeysButtonUp()
558-
apple2.ReleaseSA()
555+
apple2.Type(".")
559556
end
560557

561558
local MOUSE_KEYS_DELTA_X = 8

tests/lib/apple2.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ function apple2.ReleaseMouseButton()
552552
end
553553

554554
function apple2.ClickMouseButton()
555-
PressMouseButton()
556-
ReleaseMouseButton()
555+
apple2.PressMouseButton()
556+
apple2.ReleaseMouseButton()
557557
end
558558

559559
function apple2.DoubleClickMouseButton()

tests/name_casing.lua

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ test.Variants(
226226
{
227227
"drag - copy to another volume",
228228
"drag - move on same volume",
229-
--"drag - move to another volume", -- Uses "real" mouse, too imprecise
230-
--"drag - copy to same volume", -- Uses "real" mouse, too imprecise
229+
"drag - move to another volume", -- Uses "real" mouse, too imprecise
230+
"drag - copy to same volume", -- Uses "real" mouse, too imprecise
231231
},
232232
function(idx)
233233
EnablePreserve()
@@ -270,12 +270,13 @@ test.Variants(
270270
elseif idx == 3 then
271271
-- Move to another volume
272272

273-
-- TODO: Debug mouse usage
274273
apple2.PressSA()
275-
apple2.MoveMouse(window_x + 35, window_y + 23)
276-
apple2.PressMouseButton()
277-
apple2.MoveMouse(vol_icon4_x, vol_icon4_y)
278-
apple2.ReleaseMouseButton()
274+
a2d.InMouseKeysMode(function(m)
275+
m.MoveToApproximately(window_x + 35, window_y + 23)
276+
m.ButtonDown()
277+
m.MoveToApproximately(vol_icon4_x, vol_icon4_y)
278+
m.ButtonUp()
279+
end)
279280
apple2.ReleaseSA()
280281
a2d.WaitForRepaint()
281282

@@ -288,12 +289,13 @@ test.Variants(
288289
apple2.Type("ANOTHER.FOLDER")
289290
apple2.ReturnKey()
290291

291-
-- TODO: Debug mouse usage
292292
apple2.PressSA()
293-
a2d.MoveMouse(window_x + 45, window_y + 23)
294-
a2d.PressMouseButton()
295-
a2d.MoveMouse(80, 0)
296-
a2d.ReleaseMouseButton()
293+
a2d.InMouseKeysMode(function(m)
294+
m.MoveToApproximately(window_x + 45, window_y + 23)
295+
m.ButtonDown()
296+
m.MoveByApproximately(80, 0)
297+
m.ButtonUp()
298+
end)
297299
apple2.ReleaseSA()
298300
a2d.WaitForRepaint()
299301

tests/open.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ test.Step(
2929
local window_x, window_y = a2dtest.GetFrontWindowContentRect()
3030
a2d.InMouseKeysMode(function(m)
3131
m.MoveToApproximately(window_x + folder_icon_x, window_y + folder_icon_y)
32+
m.DoubleClick()
3233
end)
33-
apple2.DoubleClickMouseButton()
3434
a2d.WaitForRepaint()
3535

3636
test.ExpectEquals(a2dtest.GetWindowCount(), 2, "two windows should be open")
@@ -48,8 +48,8 @@ test.Step(
4848
local window_x, window_y = a2dtest.GetFrontWindowContentRect()
4949
a2d.InMouseKeysMode(function(m)
5050
m.MoveToApproximately(window_x + text_icon_x, window_y + text_icon_y)
51+
m.DoubleClick()
5152
end)
52-
apple2.DoubleClickMouseButton()
5353
a2d.WaitForRepaint()
5454

5555
test.ExpectEquals(a2dtest.GetWindowCount(), 2, "two windows should be open")
@@ -229,8 +229,8 @@ test.Step(
229229
local window_x, window_y = a2dtest.GetFrontWindowContentRect()
230230
a2d.InMouseKeysMode(function(m)
231231
m.MoveToApproximately(window_x + 40, window_y + 30)
232+
m.DoubleClick()
232233
end)
233-
apple2.DoubleClickMouseButton()
234234
a2d.WaitForRepaint()
235235

236236
test.ExpectEquals(a2dtest.GetWindowCount(), 3, "3 windows should be open")
@@ -255,8 +255,8 @@ test.Variants(
255255
a2d.SelectPath("/A2.DESKTOP/EXTRAS")
256256
a2d.InMouseKeysMode(function(m)
257257
m.MoveToApproximately(30, 5)
258+
m.Click()
258259
end)
259-
apple2.ClickMouseButton() -- if MK is used, menus remember modifier
260260

261261
local key = "O"
262262
if idx == 3 or idx == 4 then

tests/open_then_close.lua

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,49 @@ test.Step(
77
local window_x,window_y = a2dtest.GetFrontWindowContentRect()
88
a2d.InMouseKeysMode(function(m)
99
m.MoveToApproximately(window_x+30,window_x+85)
10+
apple2.PressSA()
11+
m.DoubleClick()
12+
apple2.ReleaseSA()
1013
end)
1114

12-
apple2.PressSA()
13-
apple2.DoubleClickMouseButton()
14-
a2d.WaitForRepaint()
15-
apple2.ReleaseSA()
16-
1715
test.ExpectEquals(a2dtest.GetWindowCount(), 1, "one window should be open")
1816
test.ExpectEqualsIgnoreCase(a2dtest.GetFrontWindowTitle(), "EXTRAS", "folder window should be open")
19-
20-
a2d.Reboot()
2117
end)
2218

2319
test.Step(
2420
"Solid Apple File > Open",
2521
function()
2622
a2d.SelectPath("/A2.DESKTOP/EXTRAS")
2723

28-
apple2.MoveMouse(30, 5)
29-
apple2.PressSA()
30-
apple2.ClickMouseButton()
31-
apple2.MoveMouse(30, 40)
32-
apple2.ClickMouseButton()
33-
apple2.ReleaseSA()
24+
a2d.InMouseKeysMode(function(m)
25+
m.MoveToApproximately(30, 5)
26+
apple2.PressSA()
27+
m.Click()
28+
m.MoveByApproximately(0, 25)
29+
m.Click()
30+
apple2.ReleaseSA()
31+
end)
3432

3533
test.ExpectEquals(a2dtest.GetWindowCount(), 1, "one window should be open")
3634
test.ExpectEqualsIgnoreCase(a2dtest.GetFrontWindowTitle(), "EXTRAS", "folder window should be open")
37-
38-
apple2.MoveMouse(0,0)
39-
a2d.Reboot()
4035
end)
4136

4237
test.Step(
4338
"Open Apple File > Open",
4439
function()
4540
a2d.SelectPath("/A2.DESKTOP/EXTRAS")
4641

47-
apple2.MoveMouse(30, 5)
48-
apple2.PressOA()
49-
apple2.ClickMouseButton()
50-
apple2.MoveMouse(30, 40)
51-
apple2.ClickMouseButton()
52-
apple2.ReleaseOA()
42+
a2d.InMouseKeysMode(function(m)
43+
m.MoveToApproximately(30, 5)
44+
apple2.PressOA()
45+
m.Click()
46+
m.MoveByApproximately(0, 25)
47+
m.Click()
48+
apple2.ReleaseOA()
49+
end)
5350

5451
test.ExpectEquals(a2dtest.GetWindowCount(), 1, "one window should be open")
5552
test.ExpectEqualsIgnoreCase(a2dtest.GetFrontWindowTitle(), "EXTRAS", "folder window should be open")
56-
57-
apple2.MoveMouse(0,0)
58-
a2d.Reboot()
5953
end)
6054

6155
test.Variants(
@@ -74,8 +68,6 @@ test.Variants(
7468

7569
test.ExpectEquals(a2dtest.GetWindowCount(), 1, "one window should be open")
7670
test.ExpectEqualsIgnoreCase(a2dtest.GetFrontWindowTitle(), "EXTRAS", "folder window should be open")
77-
78-
a2d.Reboot()
7971
end)
8072

8173
test.Step(
@@ -86,8 +78,6 @@ test.Step(
8678

8779
test.ExpectEquals(a2dtest.GetWindowCount(), 1, "one window should be open")
8880
test.ExpectEqualsIgnoreCase(a2dtest.GetFrontWindowTitle(), "EXTRAS", "folder window should be open")
89-
90-
a2d.Reboot()
9181
end)
9282

9383
test.Variants(
@@ -99,8 +89,8 @@ test.Variants(
9989
a2d.SelectPath("/A2.DESKTOP/EXTRAS")
10090
a2d.InMouseKeysMode(function(m)
10191
m.MoveToApproximately(30, 5)
92+
m.Click()
10293
end)
103-
apple2.ClickMouseButton() -- if MK is used, menus remember modifier
10494

10595
if idx == 1 then
10696
a2d.OASAShortcut("O")
@@ -111,8 +101,6 @@ test.Variants(
111101

112102
test.ExpectEquals(a2dtest.GetWindowCount(), 1, "one window should be open")
113103
test.ExpectEqualsIgnoreCase(a2dtest.GetFrontWindowTitle(), "EXTRAS", "folder window should be open")
114-
115-
a2d.Reboot()
116104
end)
117105

118106
test.Step(

0 commit comments

Comments
 (0)