B4J Question char to keycode?

ilan

Expert
Licensed User
Longtime User
hi, is there a snipped to convert char to keycode in b4j?

i tried using java object but could not get it working

thanx
 
Solution
The return type should be Object (I've updated my post).

I have a feeling that you are looking for the unicode code point.

B4X:
Log(Asc("a"))

ilan

Expert
Licensed User
Longtime User
B4X:
Sub KeycodeFromString(s As String) As String
 Dim jo As JavaObject
  Return jo.InitializeStatic("javafx.scene.input.KeyCode").RunMethod("getKeyCode", Array(s.ToUpperCase))
End Sub
It will return Null if there is no matching key.

oopps, i was too early with marking your answer as the solution. what i get is just the STRING back and not the KeyCode

1632912915216.png
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
The return type should be Object (I've updated my post).

I have a feeling that you are looking for the unicode code point.

B4X:
Log(Asc("a"))

exactly, this is what I was looking for. so simple!
thank you very much Erel!!
 
Upvote 0
Top