appium_client/commands/keyboard.rs
1//! Keyboard management
2use async_trait::async_trait;
3use fantoccini::error::CmdError;
4use http::Method;
5use serde_derive::{Serialize, Deserialize};
6use serde_json::json;
7use serde_repr::Serialize_repr;
8use crate::{AndroidClient, AppiumClientTrait, IOSClient};
9use crate::commands::AppiumCommand;
10
11/// Hide onscreen keyboard
12#[async_trait]
13pub trait HidesKeyboard: AppiumClientTrait {
14 /// Tries to hide keyboard using default system mechanism.
15 ///
16 /// Note: On some devices, it defaults to "swipe" or "back" button.
17 /// It unfortunately can cause side effects like going to the previous screen,
18 /// or not hiding the keyboard at all in some apps.
19 /// On iOS, the keyboard might not hide at all.
20 ///
21 /// In such cases, consider implementing your own "hide keyboard" with swipe or tap on screen.
22 async fn hide_keyboard(&self) -> Result<(), CmdError> {
23 self.issue_cmd(AppiumCommand::Custom(
24 Method::POST,
25 HIDE_KEYBOARD_ENDPOINT.to_string(),
26 Some(json!({})),
27 )).await?;
28 Ok(())
29 }
30
31 async fn hide_keyboard_with_key(&self, key_name: &str) -> Result<(), CmdError> {
32 self.issue_cmd(AppiumCommand::Custom(
33 Method::POST,
34 HIDE_KEYBOARD_ENDPOINT.to_string(),
35 Some(json!({
36 "keyName": key_name
37 })),
38 )).await?;
39 Ok(())
40 }
41
42 async fn hide_keyboard_with_strategy(&self, strategy: HideKeyboardStrategy, key_name: &str) -> Result<(), CmdError> {
43 self.issue_cmd(AppiumCommand::Custom(
44 Method::POST,
45 HIDE_KEYBOARD_ENDPOINT.to_string(),
46 Some(json!({
47 "keyName": key_name,
48 "strategy": strategy
49 })),
50 )).await?;
51 Ok(())
52 }
53}
54
55
56const HIDE_KEYBOARD_ENDPOINT: &str = "appium/device/hide_keyboard";
57
58#[async_trait]
59impl HidesKeyboard for AndroidClient {}
60
61#[async_trait]
62impl HidesKeyboard for IOSClient {}
63
64#[derive(Copy, Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
65#[serde(rename_all = "camelCase")]
66pub enum HideKeyboardStrategy {
67 Press,
68 PressKey,
69 SwipeDown,
70 TapOut,
71 TapOutside,
72 Default,
73}
74
75#[derive(Debug, Clone, Serialize)]
76pub struct KeyEvent {
77 pub keycode: AndroidKey,
78 pub metastate: u32,
79 pub flags: u32,
80}
81
82impl KeyEvent {
83 pub fn new(keycode: AndroidKey) -> KeyEvent {
84 KeyEvent {
85 keycode,
86 metastate: 0,
87 flags: 0,
88 }
89 }
90
91 pub fn with_metamodifier(self, metamodifier: AndroidKeyMetaModifier) -> Self {
92 let mut event = self;
93 event.metastate |= metamodifier.bits();
94 event
95 }
96
97 pub fn add_metamodifier(&mut self, metamodifier: AndroidKeyMetaModifier) {
98 self.metastate |= metamodifier.bits();
99 }
100
101 pub fn remove_metamodifier(&mut self, metamodifier: AndroidKeyMetaModifier) {
102 self.metastate &= !metamodifier.bits();
103 }
104
105 pub fn with_flag(self, flag: AndroidKeyFlag) -> Self {
106 let mut event = self;
107 event.flags |= flag.bits();
108 event
109 }
110
111 pub fn add_flag(&mut self, flag: AndroidKeyMetaModifier) {
112 self.flags |= flag.bits();
113 }
114
115 pub fn remove_flag(&mut self, flag: AndroidKeyMetaModifier) {
116 self.flags &= !flag.bits();
117 }
118}
119
120impl From<AndroidKey> for KeyEvent {
121 fn from(value: AndroidKey) -> Self {
122 KeyEvent {
123 keycode: value,
124 metastate: 0,
125 flags: 0,
126 }
127 }
128}
129
130/// Send key presses to device
131#[async_trait]
132pub trait PressesKey: AppiumClientTrait {
133 async fn press_key(&self, event: KeyEvent) -> Result<(), CmdError> {
134 self.issue_cmd(
135 AppiumCommand::Custom(
136 Method::POST,
137 "appium/device/press_keycode".to_string(),
138 Some(serde_json::to_value(event)?),
139 )
140 ).await?;
141
142 Ok(())
143 }
144
145 async fn long_press_key(&self, event: KeyEvent) -> Result<(), CmdError> {
146 self.issue_cmd(
147 AppiumCommand::Custom(
148 Method::POST,
149 "appium/device/long_press_keycode".to_string(),
150 Some(serde_json::to_value(event)?),
151 )
152 ).await?;
153
154 Ok(())
155 }
156}
157
158#[async_trait]
159impl PressesKey for AndroidClient {}
160
161/// Check onscreen keyboard
162#[async_trait]
163pub trait HasOnScreenKeyboard: AppiumClientTrait {
164 async fn keyboard_shown(&self) -> Result<bool, CmdError> {
165 let value = self.issue_cmd(
166 AppiumCommand::Custom(
167 Method::GET,
168 "appium/device/is_keyboard_shown".to_string(),
169 None,
170 )
171 ).await?;
172
173 Ok(serde_json::from_value(value)?)
174 }
175}
176
177#[async_trait]
178impl HasOnScreenKeyboard for AndroidClient {}
179
180#[async_trait]
181impl HasOnScreenKeyboard for IOSClient {}
182
183
184#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize_repr)]
185#[repr(u16)]
186pub enum AndroidKey {
187 /// Key code constant: Unknown key code.
188 Unknown = 0,
189
190 /// Key code constant: Soft Left key.
191 /// Usually situated below the display on phones and used as a multi-function
192 /// feature key for selecting a software defined function shown on the bottom left
193 /// of the display.
194 SoftLeft = 1,
195
196 /// Key code constant: Soft Right key.
197 /// Usually situated below the display on phones and used as a multi-function
198 /// feature key for selecting a software defined function shown on the bottom right
199 /// of the display.
200 SoftRight = 2,
201
202 /// Key code constant: Home key.
203 /// This key is handled by the framework and is never delivered to applications.
204 Home = 3,
205
206 /// Key code constant: Back key.
207 Back = 4,
208
209 /// Key code constant: Call key.
210 Call = 5,
211
212 /// Key code constant: End Call key.
213 EndCall = 6,
214
215 /// Key code constant: '0' key.
216 Digit0 = 7,
217
218 /// Key code constant: '1' key.
219 Digit1 = 8,
220
221 /// Key code constant: '2' key.
222 Digit2 = 9,
223
224 /// Key code constant: '3' key.
225 Digit3 = 10,
226
227 /// Key code constant: '4' key.
228 Digit4 = 11,
229
230 /// Key code constant: '5' key.
231 Digit5 = 12,
232
233 /// Key code constant: '6' key.
234 Digit6 = 13,
235
236 /// Key code constant: '7' key.
237 Digit7 = 14,
238
239 /// Key code constant: '8' key.
240 Digit8 = 15,
241
242 /// Key code constant: '9' key.
243 Digit9 = 16,
244
245 /// Key code constant: '*' key.
246 Asterisk = 17,
247
248 /// Key code constant: '#' key.
249 Pound = 18,
250
251 /// Key code constant: Directional Pad Up key.
252 /// May also be synthesized from trackball motions.
253 DPadUp = 19,
254
255 /// Key code constant: Directional Pad Down key.
256 /// May also be synthesized from trackball motions.
257 DPadDown = 20,
258
259 /// Key code constant: Directional Pad Left key.
260 /// May also be synthesized from trackball motions.
261 DPadLeft = 21,
262
263 /// Key code constant: Directional Pad Right key.
264 /// May also be synthesized from trackball motions.
265 DpadRight = 22,
266
267 /// Key code constant: Directional Pad Center key.
268 /// May also be synthesized from trackball motions.
269 DPadCenter = 23,
270
271 /// Key code constant: Volume Up key.
272 /// Adjusts the speaker volume up.
273 VolumeUp = 24,
274
275 /// Key code constant: Volume Down key.
276 /// Adjusts the speaker volume down.
277 VolumeDown = 25,
278
279 /// Key code constant: Power key.
280 Power = 26,
281
282 /// Key code constant: Camera key.
283 /// Used to launch a camera application or take pictures.
284 Camera = 27,
285
286 /// Key code constant: Clear key.
287 Clear = 28,
288
289 /// Key code constant: 'A' key.
290 A = 29,
291
292 /// Key code constant: 'B' key.
293 B = 30,
294
295 /// Key code constant: 'C' key.
296 C = 31,
297
298 /// Key code constant: 'D' key.
299 D = 32,
300
301 /// Key code constant: 'E' key.
302 E = 33,
303
304 /// Key code constant: 'F' key.
305 F = 34,
306
307 /// Key code constant: 'G' key.
308 G = 35,
309
310 /// Key code constant: 'H' key.
311 H = 36,
312
313 /// Key code constant: 'I' key.
314 I = 37,
315
316 /// Key code constant: 'J' key.
317 J = 38,
318
319 /// Key code constant: 'K' key.
320 K = 39,
321
322 /// Key code constant: 'L' key.
323 L = 40,
324
325 /// Key code constant: 'M' key.
326 M = 41,
327
328 /// Key code constant: 'N' key.
329 N = 42,
330
331 /// Key code constant: 'O' key.
332 O = 43,
333
334 /// Key code constant: 'P' key.
335 P = 44,
336
337 /// Key code constant: 'Q' key.
338 Q = 45,
339
340 /// Key code constant: 'R' key.
341 R = 46,
342
343 /// Key code constant: 'S' key.
344 S = 47,
345
346 /// Key code constant: 'T' key.
347 T = 48,
348
349 /// Key code constant: 'U' key.
350 U = 49,
351
352 /// Key code constant: 'V' key.
353 V = 50,
354
355 /// Key code constant: 'W' key.
356 W = 51,
357
358 /// Key code constant: 'X' key.
359 X = 52,
360
361 /// Key code constant: 'Y' key.
362 Y = 53,
363
364 /// Key code constant: 'Z' key.
365 Z = 54,
366
367 /// Key code constant: ',' key.
368 Comma = 55,
369
370 /// Key code constant: '.' key.
371 Period = 56,
372
373 /// Key code constant: Left Alt modifier key.
374 AltLeft = 57,
375
376 /// Key code constant: Right Alt modifier key.
377 AltRight = 58,
378
379 /// Key code constant: Left Shift modifier key.
380 ShiftLeft = 59,
381
382 /// Key code constant: Right Shift modifier key.
383 ShiftRight = 60,
384
385 /// Key code constant: Tab key.
386 Tab = 61,
387
388 /// Key code constant: Space key.
389 Space = 62,
390
391 /// Key code constant: Symbol modifier key.
392 /// Used to enter alternate symbols.
393 SYM = 63,
394
395 /// Key code constant: Explorer special function key.
396 /// Used to launch a browser application.
397 Explorer = 64,
398
399 /// Key code constant: Envelope special function key.
400 /// Used to launch a mail application.
401 Envelope = 65,
402
403 /// Key code constant: Enter key.
404 Enter = 66,
405
406 /// Key code constant: Backspace key.
407 /// Deletes characters before the insertion point, unlike [AndroidKey::ForwardDel].
408 DEL = 67,
409
410 /// Key code constant: '`' (backtick) key.
411 Grave = 68,
412
413 /// Key code constant: '-'.
414 Minus = 69,
415
416 /// Key code constant: '=' key.
417 Equals = 70,
418
419 /// Key code constant: '[' key.
420 LeftBracket = 71,
421
422 /// Key code constant: ']' key.
423 RightBracket = 72,
424
425 /// Key code constant: '\' key.
426 Backslash = 73,
427
428 /// Key code constant: ';' key.
429 Semicolon = 74,
430
431 /// Key code constant: ''' (apostrophe) key.
432 Apostrophe = 75,
433
434 /// Key code constant: '/' key.
435 Slash = 76,
436
437 /// Key code constant: '@' key.
438 At = 77,
439
440 /// Key code constant: Number modifier key.
441 /// Used to enter numeric symbols.
442 /// This key is not Num Lock; it is more like [AndroidKey::AltLeft] and is
443 /// interpreted as an ALT key
444 NUM = 78,
445
446 /// Key code constant: Headset Hook key.
447 /// Used to hang up calls and stop media.
448 HeadsetHook = 79,
449
450 /// Key code constant: Camera Focus key.
451 /// Used to focus the camera.
452 Focus = 80,
453
454 /// Key code constant: '+' key.
455 Plus = 81,
456
457 /// Key code constant: Menu key.
458 Menu = 82,
459
460 /// Key code constant: Notification key.
461 Notification = 83,
462
463 /// Key code constant: Search key.
464 Search = 84,
465
466 /// Key code constant: Play/Pause media key.
467 MediaPlayPause = 85,
468
469 /// Key code constant: Stop media key.
470 MediaStop = 86,
471
472 /// Key code constant: Play Next media key.
473 MediaNext = 87,
474
475 /// Key code constant: Play Previous media key.
476 MediaPrevious = 88,
477
478 /// Key code constant: Rewind media key.
479 MediaRewind = 89,
480
481 /// Key code constant: Fast Forward media key.
482 MediaFastForward = 90,
483
484 /// Key code constant: Mute key.
485 /// Mutes the microphone, unlike [AndroidKey::VolumeMute].
486 Mute = 91,
487
488 /// Key code constant: Page Up key.
489 PageUp = 92,
490
491 /// Key code constant: Page Down key.
492 PageDown = 93,
493
494 /// Key code constant: Picture Symbols modifier key.
495 /// Used to switch symbol sets (Emoji, Kao-moji).
496 PictSymbols = 94,
497
498 /// Key code constant: Switch Charset modifier key.
499 /// Used to switch character sets (Kanji, Katakana).
500 SwitchCharset = 95,
501
502 /// Key code constant: A Button key.
503 /// On a game controller, the A button should be either the button labeled A
504 /// or the first button on the bottom row of controller buttons.
505 ButtonA = 96,
506
507 /// Key code constant: B Button key.
508 /// On a game controller, the B button should be either the button labeled B
509 /// or the second button on the bottom row of controller buttons.
510 ButtonB = 97,
511
512 /// Key code constant: C Button key.
513 /// On a game controller, the C button should be either the button labeled C
514 /// or the third button on the bottom row of controller buttons.
515 ButtonC = 98,
516
517 /// Key code constant: X Button key.
518 /// On a game controller, the X button should be either the button labeled X
519 /// or the first button on the upper row of controller buttons.
520 ButtonX = 99,
521
522 /// Key code constant: Y Button key.
523 /// On a game controller, the Y button should be either the button labeled Y
524 /// or the second button on the upper row of controller buttons.
525 ButtonY = 100,
526
527 /// Key code constant: Z Button key.
528 /// On a game controller, the Z button should be either the button labeled Z
529 /// or the third button on the upper row of controller buttons.
530 ButtonZ = 101,
531
532 /// Key code constant: L1 Button key.
533 /// On a game controller, the L1 button should be either the button labeled L1 (or L)
534 /// or the top left trigger button.
535 ButtonL1 = 102,
536
537 /// Key code constant: R1 Button key.
538 /// On a game controller, the R1 button should be either the button labeled R1 (or R)
539 /// or the top right trigger button.
540 ButtonR1 = 103,
541
542 /// Key code constant: L2 Button key.
543 /// On a game controller, the L2 button should be either the button labeled L2
544 /// or the bottom left trigger button.
545 ButtonL2 = 104,
546
547 /// Key code constant: R2 Button key.
548 /// On a game controller, the R2 button should be either the button labeled R2
549 /// or the bottom right trigger button.
550 ButtonR2 = 105,
551
552 /// Key code constant: Left Thumb Button key.
553 /// On a game controller, the left thumb button indicates that the left (or only)
554 /// joystick is pressed.
555 ButtonThumbL = 106,
556
557 /// Key code constant: Right Thumb Button key.
558 /// On a game controller, the right thumb button indicates that the right
559 /// joystick is pressed.
560 ButtonThumbR = 107,
561
562 /// Key code constant: Start Button key.
563 /// On a game controller, the button labeled Start.
564 ButtonStart = 108,
565
566 /// Key code constant: Select Button key.
567 /// On a game controller, the button labeled Select.
568 ButtonSelect = 109,
569
570 /// Key code constant: Mode Button key.
571 /// On a game controller, the button labeled Mode.
572 ButtonMode = 110,
573
574 /// Key code constant: Escape key.
575 Escape = 111,
576
577 /// Key code constant: Forward Delete key.
578 /// Deletes characters ahead of the insertion point, unlike [AndroidKey::DEL].
579 ForwardDel = 112,
580
581 /// Key code constant: Left Control modifier key.
582 CtrlLeft = 113,
583
584 /// Key code constant: Right Control modifier key.
585 CtrlRight = 114,
586
587 /// Key code constant: Caps Lock key.
588 CapsLock = 115,
589
590 /// Key code constant: Scroll Lock key.
591 ScrollLock = 116,
592
593 /// Key code constant: Left Meta modifier key.
594 MetaLeft = 117,
595
596 /// Key code constant: Right Meta modifier key.
597 MetaRight = 118,
598
599 /// Key code constant: Function modifier key.
600 Function = 119,
601
602 /// Key code constant: System Request / Print Screen key.
603 SYSRQ = 120,
604
605 /// Key code constant: Break / Pause key.
606 Break = 121,
607
608 /// Key code constant: Home Movement key.
609 /// Used for scrolling or moving the cursor around to the start of a line
610 /// or to the top of a list.
611 MoveHome = 122,
612
613 /// Key code constant: End Movement key.
614 /// Used for scrolling or moving the cursor around to the end of a line
615 /// or to the bottom of a list.
616 MoveEnd = 123,
617
618 /// Key code constant: Insert key.
619 /// Toggles insert / overwrite edit mode.
620 Insert = 124,
621
622 /// Key code constant: Forward key.
623 /// Navigates forward in the history stack. Complement of [AndroidKey::Back].
624 Forward = 125,
625
626 /// Key code constant: Play media key.
627 MediaPlay = 126,
628
629 /// Key code constant: Pause media key.
630 MediaPause = 127,
631
632 /// Key code constant: Close media key.
633 /// May be used to close a CD tray, for example.
634 MediaClose = 128,
635
636 /// Key code constant: Eject media key.
637 /// May be used to eject a CD tray, for example.
638 MediaEject = 129,
639
640 /// Key code constant: Record media key.
641 MediaRecord = 130,
642
643 /// Key code constant: F1 key.
644 F1 = 131,
645
646 /// Key code constant: F2 key.
647 F2 = 132,
648
649 /// Key code constant: F3 key.
650 F3 = 133,
651
652 /// Key code constant: F4 key.
653 F4 = 134,
654
655 /// Key code constant: F5 key.
656 F5 = 135,
657
658 /// Key code constant: F6 key.
659 F6 = 136,
660
661 /// Key code constant: F7 key.
662 F7 = 137,
663
664 /// Key code constant: F8 key.
665 F8 = 138,
666
667 /// Key code constant: F9 key.
668 F9 = 139,
669
670 /// Key code constant: F10 key.
671 F10 = 140,
672
673 /// Key code constant: F11 key.
674 F11 = 141,
675
676 /// Key code constant: F12 key.
677 F12 = 142,
678
679 /// Key code constant: Num Lock key.
680 /// This is the Num Lock key; it is different from [AndroidKey::NUM].
681 /// This key alters the behavior of other keys on the numeric keypad.
682 NumLock = 143,
683
684 /// Key code constant: Numeric keypad '0' key.
685 Numpad0 = 144,
686
687 /// Key code constant: Numeric keypad '1' key.
688 Numpad1 = 145,
689
690 /// Key code constant: Numeric keypad '2' key.
691 Numpad2 = 146,
692
693 /// Key code constant: Numeric keypad '3' key.
694 Numpad3 = 147,
695
696 /// Key code constant: Numeric keypad '4' key.
697 Numpad4 = 148,
698
699 /// Key code constant: Numeric keypad '5' key.
700 Numpad5 = 149,
701
702 /// Key code constant: Numeric keypad '6' key.
703 Numpad6 = 150,
704
705 /// Key code constant: Numeric keypad '7' key.
706 Numpad7 = 151,
707
708 /// Key code constant: Numeric keypad '8' key.
709 Numpad8 = 152,
710
711 /// Key code constant: Numeric keypad '9' key.
712 Numpad9 = 153,
713
714 /// Key code constant: Numeric keypad '/' key (for division).
715 NumpadDivide = 154,
716
717 /// Key code constant: Numeric keypad '*' key (for multiplication).
718 NumpadMultiply = 155,
719
720 /// Key code constant: Numeric keypad '-' key (for subtraction).
721 NumpadSubtract = 156,
722
723 /// Key code constant: Numeric keypad '+' key (for addition).
724 NumpadAdd = 157,
725
726 /// Key code constant: Numeric keypad '.' key (for decimals or digit grouping).
727 NumpadDot = 158,
728
729 /// Key code constant: Numeric keypad ',' key (for decimals or digit grouping).
730 NumpadComma = 159,
731
732 /// Key code constant: Numeric keypad Enter key.
733 NumpadEnter = 160,
734
735 /// Key code constant: Numeric keypad '=' key.
736 NumpadEquals = 161,
737
738 /// Key code constant: Numeric keypad '(' key.
739 NumpadLeftParen = 162,
740
741 /// Key code constant: Numeric keypad ')' key.
742 NumpadRightParen = 163,
743
744 /// Key code constant: Volume Mute key.
745 /// Mutes the speaker, unlike [AndroidKey::Mute].
746 /// This key should normally be implemented as a toggle such that the first press
747 /// mutes the speaker and the second press restores the original volume.
748 VolumeMute = 164,
749
750 /// Key code constant: Info key.
751 /// Common on TV remotes to show additional information related to what is
752 /// currently being viewed.
753 Info = 165,
754
755 /// Key code constant: Channel up key.
756 /// On TV remotes, increments the television channel.
757 ChannelUp = 166,
758
759 /// Key code constant: Channel down key.
760 /// On TV remotes, decrements the television channel.
761 ChannelDown = 167,
762
763 /// Key code constant: Zoom in key.
764 KeycodeZoomIn = 168,
765
766 /// Key code constant: Zoom out key.
767 KeycodeZoomOut = 169,
768
769 /// Key code constant: TV key.
770 /// On TV remotes, switches to viewing live TV.
771 TV = 170,
772
773 /// Key code constant: Window key.
774 /// On TV remotes, toggles picture-in-picture mode or other windowing functions.
775 Window = 171,
776
777 /// Key code constant: Guide key.
778 /// On TV remotes, shows a programming guide.
779 Guide = 172,
780
781 /// Key code constant: DVR key.
782 /// On some TV remotes, switches to a DVR mode for recorded shows.
783 DVR = 173,
784
785 /// Key code constant: Bookmark key.
786 /// On some TV remotes, bookmarks content or web pages.
787 Bookmark = 174,
788
789 /// Key code constant: Toggle captions key.
790 /// Switches the mode for closed-captioning text, for example during television shows.
791 Captions = 175,
792
793 /// Key code constant: Settings key.
794 /// Starts the system settings activity.
795 Settings = 176,
796
797 /// Key code constant: TV power key.
798 /// On TV remotes, toggles the power on a television screen.
799 TVPower = 177,
800
801 /// Key code constant: TV input key.
802 /// On TV remotes, switches the input on a television screen.
803 TVInput = 178,
804
805 /// Key code constant: Set-top-box power key.
806 /// On TV remotes, toggles the power on an external Set-top-box.
807 STBPower = 179,
808
809 /// Key code constant: Set-top-box input key.
810 /// On TV remotes, switches the input mode on an external Set-top-box.
811 STBInput = 180,
812
813 /// Key code constant: A/V Receiver power key.
814 /// On TV remotes, toggles the power on an external A/V Receiver.
815 AVRPower = 181,
816
817 /// Key code constant: A/V Receiver input key.
818 /// On TV remotes, switches the input mode on an external A/V Receiver.
819 AVRInput = 182,
820
821 /// Key code constant: Red "programmable" key.
822 /// On TV remotes, acts as a contextual/programmable key.
823 ProgRed = 183,
824
825 /// Key code constant: Green "programmable" key.
826 /// On TV remotes, actsas a contextual/programmable key.
827 ProgGreen = 184,
828
829 /// Key code constant: Yellow "programmable" key.
830 /// On TV remotes, acts as a contextual/programmable key.
831 ProgYellow = 185,
832
833 /// Key code constant: Blue "programmable" key.
834 /// On TV remotes, acts as a contextual/programmable key.
835 ProgBlue = 186,
836
837 /// Key code constant: App switch key.
838 /// Should bring up the application switcher dialog.
839 AppSwitch = 187,
840
841 /// Key code constant: Generic Game Pad Button #1.
842 Button1 = 188,
843
844 /// Key code constant: Generic Game Pad Button #2.
845 Button2 = 189,
846
847 /// Key code constant: Generic Game Pad Button #3.
848 Button3 = 190,
849
850 /// Key code constant: Generic Game Pad Button #4.
851 Button4 = 191,
852
853 /// Key code constant: Generic Game Pad Button #5.
854 Button5 = 192,
855
856 /// Key code constant: Generic Game Pad Button #6.
857 Button6 = 193,
858
859 /// Key code constant: Generic Game Pad Button #7.
860 Button7 = 194,
861
862 /// Key code constant: Generic Game Pad Button #8.
863 Button8 = 195,
864
865 /// Key code constant: Generic Game Pad Button #9.
866 Button9 = 196,
867
868 /// Key code constant: Generic Game Pad Button #10.
869 Button10 = 197,
870
871 /// Key code constant: Generic Game Pad Button #11.
872 Button11 = 198,
873
874 /// Key code constant: Generic Game Pad Button #12.
875 Button12 = 199,
876
877 /// Key code constant: Generic Game Pad Button #13.
878 Button13 = 200,
879
880 /// Key code constant: Generic Game Pad Button #14.
881 Button14 = 201,
882
883 /// Key code constant: Generic Game Pad Button #15.
884 Button15 = 202,
885
886 /// Key code constant: Generic Game Pad Button #16.
887 Button16 = 203,
888
889 /// Key code constant: Language Switch key.
890 /// Toggles the current input language such as switching between English and Japanese on
891 /// a QWERTY keyboard. On some devices, the same function may be performed by
892 /// pressing Shift+Spacebar.
893 LanguageSwitch = 204,
894
895 /// Key code constant: Manner Mode key.
896 /// Toggles silent or vibrate mode on and off to make the device behave more politely
897 /// in certain settings such as on a crowded train. On some devices, the key may only
898 /// operate when long-pressed.
899 MannerMode = 205,
900
901 /// Key code constant: 3D Mode key.
902 /// Toggles the display between 2D and 3D mode.
903 Mode3D = 206,
904
905 /// Key code constant: Contacts special function key.
906 /// Used to launch an address book application.
907 Contacts = 207,
908
909 /// Key code constant: Calendar special function key.
910 /// Used to launch a calendar application.
911 Calendar = 208,
912
913 /// Key code constant: Music special function key.
914 /// Used to launch a music player application.
915 Music = 209,
916
917 /// Key code constant: Calculator special function key.
918 /// Used to launch a calculator application.
919 Calculator = 210,
920
921 /// Key code constant: Japanese full-width / half-width key.
922 ZenkakuHankaku = 211,
923
924 /// Key code constant: Japanese alphanumeric key.
925 Eisu = 212,
926
927 /// Key code constant: Japanese non-conversion key.
928 Muhenkan = 213,
929
930 /// Key code constant: Japanese conversion key.
931 Henkan = 214,
932
933 /// Key code constant: Japanese katakana / hiragana key.
934 KatakanaHiragana = 215,
935
936 /// Key code constant: Japanese Yen key.
937 Yen = 216,
938
939 /// Key code constant: Japanese Ro key.
940 Ro = 217,
941
942 /// Key code constant: Japanese kana key.
943 Kana = 218,
944
945 /// Key code constant: Assist key.
946 /// Launches the global assist activity. Not delivered to applications.
947 Assist = 219,
948
949 /// Key code constant: Brightness Down key.
950 /// Adjusts the screen brightness down.
951 BrightnessDown = 220,
952
953 /// Key code constant: Brightness Up key.
954 /// Adjusts the screen brightness up.
955 BrightnessUp = 221,
956
957 /// Key code constant: Audio Track key.
958 /// Switches the audio tracks.
959 MediaAudioTrack = 222,
960
961 /// Key code constant: Sleep key.
962 /// Puts the device to sleep. Behaves somewhat like [AndroidKey::Power] but it
963 /// has no effect if the device is already asleep.
964 Sleep = 223,
965
966 /// Key code constant: Wakeup key.
967 /// Wakes up the device. Behaves somewhat like [AndroidKey::Power] but it
968 /// has no effect if the device is already awake.
969 WakeUp = 224,
970
971 /// Key code constant: Pairing key.
972 /// Initiates peripheral pairing mode. Useful for pairing remote control
973 /// devices or game controllers, especially if no other input mode is
974 /// available.
975 Pairing = 225,
976
977 /// Key code constant: Media Top Menu key.
978 /// Goes to the top of media menu.
979 MediaTopMenu = 226,
980
981 /// Key code constant: '11' key.
982 Key11 = 227,
983
984 /// Key code constant: '12' key.
985 Key12 = 228,
986
987 /// Key code constant: Last Channel key.
988 /// Goes to the last viewed channel.
989 LastChannel = 229,
990
991 /// Key code constant: TV data service key.
992 /// Displays data services like weather, sports.
993 TVDataService = 230,
994
995 /// Key code constant: Voice Assist key.
996 /// Launches the global voice assist activity. Not delivered to applications.
997 VoiceAssist = 231,
998
999 /// Key code constant: Radio key.
1000 /// Toggles TV service / Radio service.
1001 TVRadioService = 232,
1002
1003 /// Key code constant: Teletext key.
1004 /// Displays Teletext service.
1005 TVTeletext = 233,
1006
1007 /// Key code constant: Number entry key.
1008 /// Initiates to enter multi-digit channel nubmber when each digit key is assigned
1009 /// for selecting separate channel. Corresponds to Number Entry Mode (0x1D) of CEC
1010 /// User Control Code.
1011 TVNumberEntry = 234,
1012
1013 /// Key code constant: Analog Terrestrial key.
1014 /// Switches to analog terrestrial broadcast service.
1015 TVTerrestrialAnalog = 235,
1016
1017 /// Key code constant: Digital Terrestrial key.
1018 /// Switches to digital terrestrial broadcast service.
1019 TVTerrestrialDigital = 236,
1020
1021 /// Key code constant: Satellite key.
1022 /// Switches to digital satellite broadcast service.
1023 TVSatellite = 237,
1024
1025 /// Key code constant: BS key.
1026 /// Switches to BS digital satellite broadcasting service available in Japan.
1027 TVSatelliteBS = 238,
1028
1029 /// Key code constant: CS key.
1030 /// Switches to CS digital satellite broadcasting service available in Japan.
1031 TVSatelliteCS = 239,
1032
1033 /// Key code constant: BS/CS key.
1034 /// Toggles between BS and CS digital satellite services.
1035 TVSatelliteService = 240,
1036
1037 /// Key code constant: Toggle Network key.
1038 /// Toggles selecting broacast services.
1039 TVNetwork = 241,
1040
1041 /// Key code constant: Antenna/Cable key.
1042 /// Toggles broadcast input source between antenna and cable.
1043 TVAntennaCable = 242,
1044
1045 /// Key code constant: HDMI #1 key.
1046 /// Switches to HDMI input #1.
1047 TVInputHdmi1 = 243,
1048
1049 /// Key code constant: HDMI #2 key.
1050 /// Switches to HDMI input #2.
1051 TVInputHdmi2 = 244,
1052
1053 /// Key code constant: HDMI #3 key.
1054 /// Switches to HDMI input #3.
1055 TVInputHdmi3 = 245,
1056
1057 /// Key code constant: HDMI #4 key.
1058 /// Switches to HDMI input #4.
1059 TVInputHdmi4 = 246,
1060
1061 /// Key code constant: Composite #1 key.
1062 /// Switches to composite video input #1.
1063 TVInputComposite1 = 247,
1064
1065 /// Key code constant: Composite #2 key.
1066 /// Switches to composite video input #2.
1067 TVInputComposite2 = 248,
1068
1069 /// Key code constant: Component #1 key.
1070 /// Switches to component video input #1.
1071 TVInputComponent1 = 249,
1072
1073 /// Key code constant: Component #2 key.
1074 /// Switches to component video input #2.
1075 TVInputComponent2 = 250,
1076
1077 /// Key code constant: VGA #1 key.
1078 /// Switches to VGA (analog RGB) input #1.
1079 TVInputVga1 = 251,
1080
1081 /// Key code constant: Audio description key.
1082 /// Toggles audio description off / on.
1083 TVAudioDescription = 252,
1084
1085 /// Key code constant: Audio description mixing volume up key.
1086 /// Louden audio description volume as compared with normal audio volume.
1087 TVAudioDescriptionMixUp = 253,
1088
1089 /// Key code constant: Audio description mixing volume down key.
1090 /// Lessen audio description volume as compared with normal audio volume.
1091 TVAudioDescriptionMixDown = 254,
1092
1093 /// Key code constant: Zoom mode key.
1094 /// Changes Zoom mode (Normal, Full, Zoom, Wide-zoom, etc.)
1095 TVZoomMode = 255,
1096
1097 /// Key code constant: Contents menu key.
1098 /// Goes to the title list. Corresponds to Contents Menu (0x0B) of CEC User Control
1099 /// Code
1100 TVContentsMenu = 256,
1101
1102 /// Key code constant: Media context menu key.
1103 /// Goes to the context menu of media contents. Corresponds to Media Context-sensitive
1104 /// Menu (0x11) of CEC User Control Code.
1105 TVMediaContextMenu = 257,
1106
1107 /// Key code constant: Timer programming key.
1108 /// Goes to the timer recording menu. Corresponds to Timer Programming (0x54) of
1109 /// CEC User Control Code.
1110 TVTimerProgramming = 258,
1111
1112 /// Key code constant: Help key.
1113 Help = 259,
1114
1115 /// Key code constant: Navigate to previous key.
1116 /// Goes backward by one item in an ordered collection of items.
1117 NavigatePrevious = 260,
1118
1119 /// Key code constant: Navigate to next key.
1120 /// Advances to the next item in an ordered collection of items.
1121 NavigateNext = 261,
1122
1123 /// Key code constant: Navigate in key.
1124 /// Activates the item that currently has focus or expands to the next level of a navigation
1125 /// hierarchy.
1126 NavigateIn = 262,
1127
1128 /// Key code constant: Navigate out key.
1129 /// Backs out one level of a navigation hierarchy or collapses the item that currently has
1130 /// focus.
1131 NavigateOut = 263,
1132
1133 /// Key code constant: Primary stem key for Wear.
1134 /// Main power/reset button on watch.
1135 StemPrimary = 264,
1136
1137 /// Key code constant: Generic stem key 1 for Wear.
1138 Stem1 = 265,
1139
1140 /// Key code constant: Generic stem key 2 for Wear.
1141 Stem2 = 266,
1142
1143 /// Key code constant: Generic stem key 3 for Wear.
1144 Stem3 = 267,
1145
1146 /// Key code constant: Directional Pad Up-Left.
1147 DpadUpLeft = 268,
1148
1149 /// Key code constant: Directional Pad Down-Left.
1150 DpadDownLeft = 269,
1151
1152 /// Key code constant: Directional Pad Up-Right.
1153 DpadUpRight = 270,
1154
1155 /// Key code constant: Directional Pad Down-Right.
1156 DpadDownRight = 271,
1157
1158 /// Key code constant: Skip forward media key.
1159 MediaSkipForward = 272,
1160
1161 /// Key code constant: Skip backward media key.
1162 MediaSkipBackward = 273,
1163
1164 /// Key code constant: Step forward media key.
1165 /// Steps media forward, one frame at a time.
1166 MediaStepForward = 274,
1167
1168 /// Key code constant: Step backward media key.
1169 /// Steps media backward, one frame at a time.
1170 MediaStepBackward = 275,
1171
1172 /// Key code constant: put device to sleep unless a wakelock is held.
1173 SoftSleep = 276,
1174
1175 /// Key code constant: Cut key.
1176 Cut = 277,
1177
1178 /// Key code constant: Copy key.
1179 Copy = 278,
1180
1181 /// Key code constant: Paste key.
1182 Paste = 279,
1183}
1184
1185
1186bitflags::bitflags! {
1187 #[repr(transparent)]
1188 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1189 pub struct AndroidKeyMetaModifier: u32 {
1190
1191 /// SHIFT key locked in CAPS mode.
1192 /// Reserved for use by MetaKeyKeyListener for a published constant in its API.
1193 const CAP_LOCKED = 0x100;
1194
1195 /// ALT key locked.
1196 /// Reserved for use by MetaKeyKeyListener for a published constant in its API.
1197 const ALT_LOCKED = 0x200;
1198
1199 /// SYM key locked.
1200 /// Reserved for use by MetaKeyKeyListener for a published constant in its API.
1201 const SYM_LOCKED = 0x400;
1202
1203 /// Text is in selection mode.
1204 /// Reserved for use by MetaKeyKeyListener for a private unpublished constant
1205 /// in its API that is currently being retained for legacy reasons.
1206 const SELECTING = 0x800;
1207
1208 /// This mask is used to check whether one of the ALT meta keys is pressed.
1209 ///
1210 /// See also [AndroidKey::AltLeft] and [AndroidKey::AltRight]
1211 const ALT_ON = 0x02;
1212
1213 /// This mask is used to check whether the left ALT meta key is pressed.
1214 ///
1215 /// See also [AndroidKey::AltLeft]
1216 const ALT_LEFT_ON = 0x10;
1217
1218 /// This mask is used to check whether the right the ALT meta key is pressed.
1219 ///
1220 /// See also [AndroidKey::AltRight]
1221 const ALT_RIGHT_ON = 0x20;
1222
1223 /// This mask is used to check whether one of the SHIFT meta keys is pressed.
1224 ///
1225 /// See also [AndroidKey::ShiftLeft] and [AndroidKey::ShiftRight]
1226 const SHIFT_ON = 0x1;
1227
1228 /// This mask is used to check whether the left SHIFT meta key is pressed.
1229 ///
1230 /// See also [AndroidKey::ShiftLeft]
1231 const SHIFT_LEFT_ON = 0x40;
1232
1233 /// This mask is used to check whether the right SHIFT meta key is pressed.
1234 ///
1235 /// See also [AndroidKey::ShiftRight]
1236 const SHIFT_RIGHT_ON = 0x80;
1237
1238 /// This mask is used to check whether the SYM meta key is pressed.
1239 const SYM_ON = 0x4;
1240
1241 /// This mask is used to check whether the FUNCTION meta key is pressed.
1242 const FUNCTION_ON = 0x8;
1243
1244 /// This mask is used to check whether one of the CTRL meta keys is pressed.
1245 ///
1246 /// See also [AndroidKey::CtrlLeft] and [AndroidKey::CtrlRight]
1247 const CTRL_ON = 0x1000;
1248
1249 /// This mask is used to check whether the left CTRL meta key is pressed.
1250 ///
1251 /// See also [AndroidKey::CtrlLeft]
1252 const CTRL_LEFT_ON = 0x2000;
1253
1254 /// This mask is used to check whether the right CTRL meta key is pressed.
1255 ///
1256 /// See also [AndroidKey::CtrlRight]
1257 const CTRL_RIGHT_ON = 0x4000;
1258
1259 /// This mask is used to check whether one of the META meta keys is pressed.
1260 ///
1261 /// See also [AndroidKey::MetaLeft] and [AndroidKey::MetaRight].
1262 const META_ON = 0x10000;
1263
1264 /// This mask is used to check whether the left META meta key is pressed.
1265 ///
1266 /// See also [AndroidKey::MetaLeft]
1267 const META_LEFT_ON = 0x20000;
1268
1269 /// This mask is used to check whether the right META meta key is pressed.
1270 ///
1271 /// See also [AndroidKey::MetaRight]
1272 const META_RIGHT_ON = 0x40000;
1273
1274 /// This mask is used to check whether the CAPS LOCK meta key is on.
1275 ///
1276 /// See also [AndroidKey::CapsLock]
1277 const CAPS_LOCK_ON = 0x100000;
1278
1279 /// This mask is used to check whether the NUM LOCK meta key is on.
1280 ///
1281 /// See also [AndroidKey::NumLock]
1282 const NUM_LOCK_ON = 0x200000;
1283
1284 /// This mask is used to check whether the SCROLL LOCK meta key is on.
1285 ///
1286 /// See also [AndroidKey::ScrollLock]
1287 const SCROLL_LOCK_ON = 0x400000;
1288 }
1289}
1290
1291
1292bitflags::bitflags! {
1293 #[repr(transparent)]
1294 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1295 pub struct AndroidKeyFlag: u32 {
1296
1297 /// This mask is set if the key event was generated by a software keyboard.
1298 const SOFT_KEYBOARD = 0x2;
1299
1300 /// This mask is set if we don't want the key event to cause us to leave
1301 /// touch mode.
1302 const KEEP_TOUCH_MODE = 0x4;
1303
1304 /// This mask is set if an event was known to come from a trusted part
1305 /// of the system. That is, the event is known to come from the user,
1306 /// and could not have been spoofed by a third party component.
1307 const FROM_SYSTEM = 0x8;
1308
1309 /// This mask is used for compatibility, to identify enter keys that are
1310 /// coming from an IME whose enter key has been auto-labelled "next" or
1311 /// "done". This allows TextView to dispatch these as normal enter keys
1312 /// for old applications, but still do the appropriate action when
1313 /// receiving them.
1314 const EDITOR_ACTION = 0x10;
1315
1316 /// When associated with up key events, this indicates that the key press
1317 /// has been canceled. Typically this is used with virtual touch screen
1318 /// keys, where the user can slide from the virtual key area on to the
1319 /// display: in that case, the application will receive a canceled up
1320 /// event and should not perform the action normally associated with the
1321 /// key. Note that for this to work, the application can not perform an
1322 /// action for a key until it receives an up or the long press timeout has
1323 /// expired.
1324 const CANCELED = 0x20;
1325
1326 /// This key event was generated by a virtual (on-screen) hard key area.
1327 /// Typically this is an area of the touchscreen, outside of the regular
1328 /// display, dedicated to "hardware" buttons.
1329 const VIRTUAL_HARD_KEY = 0x40;
1330
1331 /// This flag is set for the first key repeat that occurs after the
1332 /// long press timeout.
1333 const LONG_PRESS = 0x80;
1334
1335 /// Set when a key event has [AndroidKeyFlag::CANCELED] set because a long
1336 /// press action was executed while it was down.
1337 const CANCELED_LONG_PRESS = 0x100;
1338
1339 /// Set for ACTION_UP when this event's key value is still being
1340 /// tracked from its initial down. That is, somebody requested that tracking
1341 /// started on the key down and a long press has not caused
1342 /// the tracking to be canceled.
1343 const TRACKING = 0x200;
1344
1345 /// Set when a key event has been synthesized to implement default behavior
1346 /// for an event that the application did not handle.
1347 /// Fallback key events are generated by unhandled trackball motions
1348 /// (to emulate a directional keypad) and by certain unhandled key presses
1349 /// that are declared in the key map (such as special function numeric keypad
1350 /// keys when numlock is off).
1351 const FALLBACK = 0x400;
1352
1353 /// Signifies that the key is being predispatched.
1354 const PREDISPATCH = 0x20000000;
1355
1356 /// Private control to determine when an app is tracking a key sequence.
1357 const START_TRACKING = 0x40000000;
1358
1359 /// Private flag that indicates when the system has detected that this key event
1360 /// may be inconsistent with respect to the sequence of previously delivered key events,
1361 /// such as when a key up event is sent but the key was not down.
1362 const TAINTED = 0x80000000;
1363 }
1364}
1365