Key Binding to a Subroutine

ohkovar

Member
Licensed User
Is there a way to bind keys to call a particular subroutine? For instance, I have a login screen when the app starts. I have a special admin password that
will allow me to bypass the user's password and login (for debugging someone's device). I would like to have a special Ctrl+Shift+A or something similar to automatically call a login subroutine to login me in.

Thanks in advance!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use the door library to do it (the source code is attached):
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    Form1.Show
    obj.New1(False)
    obj.FromControl("Form1") 'Get a reference to the relevant form.
    obj.SetProperty("KeyPreview",True) 'Setting the KeyPreview property to true will allow the form KeyPress event to handle all key presses.
    keypress.New1(obj.Value,"KeyDown") 'Catch the KeyDown event.
End Sub

Sub keypress_NewEvent
    obj.Value = keypress.Data
    If obj.GetProperty("Control") = True AND obj.GetProperty("Alt") = True AND obj.GetProperty("KeyCode") = "E" Then
        Msgbox("Ctrl+Alt+E was pressed.")
    End If
End Sub
 

Attachments

  • 1.sbp
    631 bytes · Views: 184

ohkovar

Member
Licensed User
Okay, what is the obj object? I'm getting the following error (runtime error):

obj.New1(False)
Object reference not set to an instance of an object.
 

Byak@

Active Member
Licensed User
Erel and what about get keypress event if my form not in forward?my form is minimized.
 

Byak@

Active Member
Licensed User
Erel please show me example.when i do it program catch only cursor buttons.
 

Byak@

Active Member
Licensed User
heh,problem with my AEbutton+.i'm kill it and algoritm work.i catch all buttons?but button "Call" (114) doesnot catch.BUT attached proram(keycode.exe) catch all my buttons.why?
 

Attachments

  • keycode.zip
    2.5 KB · Views: 174
Top