Ascii codes/keycodes

Rusty

Well-Known Member
Licensed User
Longtime User
I note that when I test my app with the computer keyboard and emulator, i get keycodes that don't appear to be ascii compliant. i.e. the "5" key generates a keycode of 12 instead of the Ascii code 53. Is this something associated with the emulator and having a keyboard attached? When the app is installed on a device, will these codes be consistent or will the keycodes be Ascii?
 

qsrtech

Active Member
Licensed User
Longtime User
keycodes to ascii

Is there a formula so we can convert the keycodes to the appropriate ascii codes? I'm integrating a handheld barcode scanner and I need to map the keys to the appropriate values. btw, the help doesn't say what value each keycode is.

Thanks!
John
 
Upvote 0

qsrtech

Active Member
Licensed User
Longtime User
keycode to character?

Thank you for the info. So without doing a select case for every possible keycode is there a function such as chr() that can map the keycode to a character?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
   Dim s As String = ""
   If KeyCode >= KeyCodes.KEYCODE_0 AND KeyCode <= KeyCodes.KEYCODE_9 Then
      s = Chr(KeyCode + 41)
   Else If KeyCode >= KeyCodes.KEYCODE_A AND KeyCode <= KeyCodes.KEYCODE_Z Then
      s = Chr(KeyCode + 36)
   End If
   If s <> "" Then 
          Log(s)
          Return True
        End If
End Sub
 
Upvote 0
Top