Skip to content

Commit 1080c8b

Browse files
kjaroshadrian17
authored andcommitted
tests: Add button_keypress_vs_tab test
This test verifies that the KeyPress event handling has precedence over tabbing.
1 parent 0edb7d6 commit 1080c8b

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{ "type": "KeyDown", "key_code": 9 },
3+
{ "type": "TextInput", "codepoint": "\t" },
4+
{ "type": "KeyUp", "key_code": 9 },
5+
{ "type": "KeyDown", "key_code": 9 },
6+
{ "type": "TextInput", "codepoint": "\t" },
7+
{ "type": "KeyUp", "key_code": 9 },
8+
{ "type": "KeyDown", "key_code": 27 },
9+
{ "type": "KeyUp", "key_code": 27 },
10+
{ "type": "KeyDown", "key_code": 9 },
11+
{ "type": "TextInput", "codepoint": "\t" },
12+
{ "type": "KeyUp", "key_code": 9 },
13+
{ "type": "KeyDown", "key_code": 9 },
14+
{ "type": "TextInput", "codepoint": "\t" },
15+
{ "type": "KeyUp", "key_code": 9 }
16+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Focus changed: null -> _level0.button1
2+
button.onKeyDown: 9
3+
Tab pressed
4+
Focus changed: _level0.button1 -> _level0.button2
5+
button.onKeyUp: 9
6+
button.onKeyDown: 9
7+
Tab pressed
8+
Focus changed: _level0.button2 -> _level0.button1
9+
button.onKeyUp: 9
10+
button.onKeyDown: 27
11+
===== Escape pressed
12+
button.onKeyUp: 27
13+
button.onKeyDown: 9
14+
Tab pressed
15+
keyPress 3 tab
16+
button.onKeyUp: 9
17+
button.onKeyDown: 9
18+
Tab pressed
19+
keyPress 3 tab
20+
button.onKeyUp: 9
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var listener = new Object();
2+
listener.onKeyDown = function() {
3+
if (Key.getCode() == 9) {
4+
trace("Tab pressed");
5+
}
6+
if (Key.getCode() == 27) {
7+
trace("===== Escape pressed");
8+
9+
button2._visible = false;
10+
button3._visible = true;
11+
Selection.setFocus(button1);
12+
}
13+
};
14+
listener.onSetFocus = function(oldFocus, newFocus) {
15+
if (newFocus) {
16+
trace("Focus changed: " + oldFocus + " -> " + newFocus);
17+
}
18+
};
19+
Key.addListener(listener);
20+
Selection.addListener(listener);
21+
22+
button1.tabIndex = 1;
23+
button2.tabIndex = 2;
24+
button3.tabIndex = 3;
25+
26+
var buttons = [button1, button2, button3];
27+
for (var i in buttons) {
28+
buttons[i].onKeyDown = function () { trace("button.onKeyDown: " + Key.getCode()); }
29+
buttons[i].onKeyUp = function () { trace("button.onKeyUp: " + Key.getCode()); }
30+
buttons[i].onPress = function () { trace("button.onPress: " + Key.getCode()); }
31+
buttons[i].onRelease = function () { trace("button.onRelease: " + Key.getCode()); }
32+
}
33+
34+
button3._visible = false;
35+
Selection.setFocus(button1);
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
num_ticks = 1

0 commit comments

Comments
 (0)