Jump to content
sneg74ok

How to intercept the bluetooth joystick button press when the screen is locked.

Recommended Posts

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.

87.jpg

16.PNG

KeyCodeReceiver.7z

Share this post


Link to post

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

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

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 by Rollo62

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×