CHackbart 13 Posted May 7 (edited) Hi, i am a bit clueless. All the buttons on the remote are not detected, except the cursor keys. My code is quite simple: protected procedure IsDialogKey(const Key: Word; const KeyChar: WideChar; const Shift: TShiftState; var IsDialog: Boolean); override; public ... procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: WideChar; Shift: TShiftState); begin SendKey(Key, KeyChar); end; procedure TForm1.IsDialogKey(const Key: Word; const KeyChar: WideChar; const Shift: TShiftState; var IsDialog: Boolean); begin SendKey(Key, KeyChar); inherited; end; procedure TForm1.SendKey(const AKey: Word; const AKeyChar: WideChar); begin Label1.Text := format('%d - %s (%d)', [AKey, AKeyChar, ord(AKeyChar)]); end; The form only has a Label. I got a IsDialogKey event triggered when pressing, but Key and AKeyChar are 0 in every case - except when the cursor keys are pressed. Does someone have an idea? When I set a breakpoint at function TAndroidTextInputManager.HandleAndroidKeyEvent(AEvent: PAInputEvent): Int32; I see that my keys are detected well, but got lost in PlatformKeyToVirtualKey *wth*. I have to register all keys which are available for this certain platform. Christian Edited May 7 by CHackbart Share this post Link to post
Dave Nottage 557 Posted May 8 22 hours ago, CHackbart said: All the buttons on the remote are not detected, except the cursor keys. That's likely because there's only a few supported, including the arrow keys. This is some code I used a while ago in a TV app, which I have not touched in some time: type TKeyNavigation = (None, Home, Back, Left, Right, Up, Down, OK); // KeyUp method is overridden from TForm procedure TExampleForm.KeyUp(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); var LKeyNavigation: TKeyNavigation; LIsTV: Boolean; begin // For the following code, please refer to: // https://github.com/DelphiWorlds/Kastri/blob/c01b93369c2c33f8ab22acad611939be4789aae6/Core/DW.OSDevice.Android.pas#L216 // and: // https://github.com/DelphiWorlds/Kastri/blob/c01b93369c2c33f8ab22acad611939be4789aae6/Core/DW.OSDevice.pas#L34 LIsTV := TOSDevice.GetUIMode = TUIMode.Television; LKeyNavigation := TKeyNavigation.None; case Key of vkHardwareBack, vkEscape: LKeyNavigation := TKeyNavigation.Back; vkleft: LKeyNavigation := TKeyNavigation.Left; vkUp: LKeyNavigation := TKeyNavigation.Up; vkRight: LKeyNavigation := TKeyNavigation.Right; vkDown: LKeyNavigation := TKeyNavigation.Down; 0, vkReturn: begin if KeyChar = #0 then LKeyNavigation := TKeyNavigation.OK; end; end; if FPreventExit and ((Key = vkHardwareBack) or (LIsTV and (Key = vkEscape))) then begin Key := 0; KeyChar := #0; end; if (LKeyNavigation <> TKeyNavigation.None) and LIsTV then KeyNavigation(LKeyNavigation); end; procedure TExampleForm.KeyNavigation(const ANavigation: TKeyNavigation); begin // Use this method to determine what to do with the navigation key end; Looking at it again now, it probably needs more work. Share this post Link to post
CHackbart 13 Posted May 8 const DefaultKeys: Array [0 .. 284] of integer = ( (* soft_left *) 1, (* soft_right *) 2, (* home *) 3, (* back *) 4, (* call *) 5, (* endcall *) 6, (* 0 *) 7, (* 1 *) 8, (* 2 *) 9, (* 3 *) 10, (* 4 *) 11, (* 5 *) 12, (* 6 *) 13, (* 7 *) 14, (* 8 *) 15, (* 9 *) 16, (* star *) 17, (* pound *) 18, (* dpad_up *) 19, (* dpad_down *) 20, (* dpad_left *) 21, (* dpad_right *) 22, (* dpad_center *) 23, (* volume_up *) 24, (* volume_down *) 25, (* power *) 26, (* camera *) 27, (* clear *) 28, (* a *) 29, (* b *) 30, (* c *) 31, (* d *) 32, (* e *) 33, (* f *) 34, (* g *) 35, (* h *) 36, (* i *) 37, (* j *) 38, (* k *) 39, (* l *) 40, (* m *) 41, (* n *) 42, (* o *) 43, (* p *) 44, (* q *) 45, (* r *) 46, (* s *) 47, (* t *) 48, (* u *) 49, (* v *) 50, (* w *) 51, (* x *) 52, (* y *) 53, (* z *) 54, (* comma *) 55, (* period *) 56, (* alt_left *) 57, (* alt_right *) 58, (* shift_left *) 59, (* shift_right *) 60, (* tab *) 61, (* space *) 62, (* sym *) 63, (* explorer *) 64, (* envelope *) 65, (* enter *) 66, (* del *) 67, (* grave *) 68, (* minus *) 69, (* equals *) 70, (* left_bracket *) 71, (* right_bracket *) 72, (* backslash *) 73, (* semicolon *) 74, (* apostrophe *) 75, (* slash *) 76, (* at *) 77, (* num *) 78, (* headsethook *) 79, (* focus *) 80, (* plus *) 81, (* menu *) 82, (* notification *) 83, (* search *) 84, (* media_play_pause *) 85, (* media_stop *) 86, (* media_next *) 87, (* media_previous *) 88, (* media_rewind *) 89, (* media_fast_forward *) 90, (* mute *) 91, (* page_up *) 92, (* page_down *) 93, (* pictsymbols *) 94, (* switch_charset *) 95, (* button_a *) 96, (* button_b *) 97, (* button_c *) 98, (* button_x *) 99, (* button_y *) 100, (* button_z *) 101, (* button_l1 *) 102, (* button_r1 *) 103, (* button_l2 *) 104, (* button_r2 *) 105, (* button_thumbl *) 106, (* button_thumbr *) 107, (* button_start *) 108, (* button_select *) 109, (* button_mode *) 110, (* escape *) 111, (* forward_del *) 112, (* ctrl_left *) 113, (* ctrl_right *) 114, (* caps_lock *) 115, (* scroll_lock *) 116, (* meta_left *) 117, (* meta_right *) 118, (* function *) 119, (* sysrq *) 120, (* break *) 121, (* move_home *) 122, (* move_end *) 123, (* insert *) 124, (* forward *) 125, (* media_play *) 126, (* media_pause *) 127, (* media_close *) 128, (* media_eject *) 129, (* media_record *) 130, (* f1 *) 131, (* f2 *) 132, (* f3 *) 133, (* f4 *) 134, (* f5 *) 135, (* f6 *) 136, (* f7 *) 137, (* f8 *) 138, (* f9 *) 139, (* f10 *) 140, (* f11 *) 141, (* f12 *) 142, (* num_lock *) 143, (* numpad_0 *) 144, (* numpad_1 *) 145, (* numpad_2 *) 146, (* numpad_3 *) 147, (* numpad_4 *) 148, (* numpad_5 *) 149, (* numpad_6 *) 150, (* numpad_7 *) 151, (* numpad_8 *) 152, (* numpad_9 *) 153, (* numpad_divide *) 154, (* numpad_multiply *) 155, (* numpad_subtract *) 156, (* numpad_add *) 157, (* numpad_dot *) 158, (* numpad_comma *) 159, (* numpad_enter *) 160, (* numpad_equals *) 161, (* numpad_left_paren *) 162, (* numpad_right_paren *) 163, (* volume_mute *) 164, (* info *) 165, (* channel_up *) 166, (* channel_down *) 167, (* zoom_in *) 168, (* zoom_out *) 169, (* tv *) 170, (* window *) 171, (* guide *) 172, (* dvr *) 173, (* bookmark *) 174, (* captions *) 175, (* settings *) 176, (* tv_power *) 177, (* tv_input *) 178, (* stb_power *) 179, (* stb_input *) 180, (* avr_power *) 181, (* avr_input *) 182, (* prog_red *) 183, (* prog_green *) 184, (* prog_yellow *) 185, (* prog_blue *) 186, (* app_switch *) 187, (* button_1 *) 188, (* button_2 *) 189, (* button_3 *) 190, (* button_4 *) 191, (* button_5 *) 192, (* button_6 *) 193, (* button_7 *) 194, (* button_8 *) 195, (* button_9 *) 196, (* button_10 *) 197, (* button_11 *) 198, (* button_12 *) 199, (* button_13 *) 200, (* button_14 *) 201, (* button_15 *) 202, (* button_16 *) 203, (* language_switch *) 204, (* manner_mode *) 205, (* 3d_mode *) 206, (* contacts *) 207, (* calendar *) 208, (* music *) 209, (* calculator *) 210, (* zenkaku_hankaku *) 211, (* eisu *) 212, (* muhenkan *) 213, (* henkan *) 214, (* katakana_hiragana *) 215, (* yen *) 216, (* ro *) 217, (* kana *) 218, (* assist *) 219, (* brightness_down *) 220, (* brightness_up *) 221, (* media_audio_track *) 222, (* sleep *) 223, (* wakeup *) 224, (* pairing *) 225, (* media_top_menu *) 226, (* 11 *) 227, (* 12 *) 228, (* last_channel *) 229, (* tv_data_service *) 230, (* voice_assist *) 231, (* tv_radio_service *) 232, (* tv_teletext *) 233, (* tv_number_entry *) 234, (* tv_terrestrial_analog *) 235, (* tv_terrestrial_digital *) 236, (* tv_satellite *) 237, (* tv_satellite_bs *) 238, (* tv_satellite_cs *) 239, (* tv_satellite_service *) 240, (* tv_network *) 241, (* tv_antenna_cable *) 242, (* tv_input_hdmi_1 *) 243, (* tv_input_hdmi_2 *) 244, (* tv_input_hdmi_3 *) 245, (* tv_input_hdmi_4 *) 246, (* tv_input_composite_1 *) 247, (* tv_input_composite_2 *) 248, (* tv_input_component_1 *) 249, (* tv_input_component_2 *) 250, (* tv_input_vga_1 *) 251, (* tv_audio_description *) 252, (* tv_audio_description_mix_up *) 253, (* tv_audio_description_mix_down *) 254, (* tv_zoom_mode *) 255, (* tv_contents_menu *) 256, (* tv_media_context_menu *) 257, (* tv_timer_programming *) 258, (* help *) 259, (* navigate_previous *) 260, (* navigate_next *) 261, (* navigate_in *) 262, (* navigate_out *) 263, (* stem_primary *) 264, (* stem_1 *) 265, (* stem_2 *) 266, (* stem_3 *) 267, (* dpad_up_left *) 268, (* dpad_down_left *) 269, (* dpad_up_right *) 270, (* dpad_down_right *) 271, (* media_skip_forward *) 272, (* media_skip_backward *) 273, (* media_step_forward *) 274, (* media_step_backward *) 275, (* soft_sleep *) 276, (* cut *) 277, (* copy *) 278, (* paste *) 279, (* system_navigation_up *) 280, (* system_navigation_down *) 281, (* system_navigation_left *) 282, (* system_navigation_right *) 283, (* all_apps *) 284, (* refresh *) 285); .. if TPlatformServices.Current.SupportsPlatformService(IFMXKeyMappingService, KeyMappingService) then begin for i := 0 to high(DefaultKeys) do KeyMappingService.RegisterKeyMapping(DefaultKeys[i], DefaultKeys[i], TKeyKind.Usual); end; Thanks, I use the code above which seem to work fine with the remotes. 1 Share this post Link to post
MarcioD 0 Posted May 13 (edited) CHackbart - thank you 🙂 Edited May 13 by MarcioD Share this post Link to post
MarcioD 0 Posted May 14 (edited) CHackbart - Do the "volume up, volume down and volume mute" keys work for you? Edited May 14 by MarcioD Share this post Link to post