sneg74ok 0 Posted January 12, 2023 Hi All! I have a joystick that is connected to my phone. When my application is running a can see than joysticks buttons are pressing. But when the phone screen is locked, I don't see notifications about it in my app. What can I do to receive joystick button press in my application when the screen is locked? Receivers code procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin inc(i); Memo1.Lines.Add('i=' + IntToStr(i) + '; Key=' + IntToStr(Key)); end; The result of the application, photos of joysticks and the source code are in the attachment. KeyCodeReceiver.7z Share this post Link to post
programmerdelphi2k 237 Posted January 13, 2023 if you screen is "locked", then, you'll need allow any key from external-keyboard/joystick unlock it/wake-up. In Android is possible add a Bluetooth-Device in: Setting-> Security -> Smart Lock -> Trusted Devices... Share this post Link to post
sneg74ok 0 Posted January 13, 2023 Thanks for suggestion but I don't want unlock screen. I just want receive message about button was pressed. This app have to works like audio player, in the background. And when the joystick button is pressed, the player have to shift forward two seconds. Share this post Link to post
Rollo62 536 Posted January 13, 2023 (edited) Interesting question. I would think that the problem is that your app sleeps in doze mode, and there is no real reason to permit it running. When in foreground then the TForm can read those key events, but in background you could try to use an Android Service. Maybe this method works still within a service, but I doubt that you will get an background permission easily without certain hacks. Quote Your game can receive these input events by implementing the following callback methods in your active Activity or focused View (you should implement the callbacks for either the Activity or View, but not both): Maybe you can look after howto receive the volume key from music player apps in the background, there were some possibilities too, but the main difference seems to be that a music player app is allowed to run in background. You must consider that reading keys in background would be a large security issue (like rading passwords from external keyboards), so I would think Android strictly forbids that. Edited January 13, 2023 by Rollo62 Share this post Link to post