### List of Key Codes

An example of getting a map holding KeyName = KeyCode using Inline Java (requires the JavaObject library).
B4J Code Non-UI Application
`Sub Process_Globals
Private joInLine As JavaObject = Me
End Sub`
`Sub AppStart (Args() As String)
Dim m As Map = joInLine.RunMethod("getkeyfieldsmap", Null)
Log("List of KeyName with KeyCodes")
For i = 0 To m.Size - 1
Log(m.GetKeyAt(i) & " = " & m.GetValueAt(i))
Next
ExitApplication
End Sub`
If JAVA
import java.awt.event.KeyEvent;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import anywheresoftware.b4a.objects.collections.Map;
public static Map.MyMap getkeyfieldsmap() throws IllegalArgumentException, IllegalAccessException, ClassNotFoundException {
Map.MyMap keymap = new Map.MyMap();
for (Field f : KeyEvent.class.getDeclaredFields()) {
if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) {
f.setAccessible(true);
Map m = new Map();
m.Initialize();
m.Put(f.getName(), f.get(null));
// System.out.println(f.getName() + ", " + f.get(null));
keymap.putAll(m.getObject());
}
}
return keymap;
}
End if
Output Example
List of KeyName with KeyCodes
KEY_FIRST = 400
KEY_LAST = 402
KEY_TYPED = 400
Etc.

Changed: 2018-04-22 09:24, Category: KeyEvents, File: T6C211M1544.htm, ID: 1544