Pregunta

I want to increment value of keyevent.VK parameter using program. I tried below code which print one "r.keyPress(KeyEvent.VK_1);" upon execution of this code it prints 1. I want program should automatically increase the values using any loop. please help

¿Fue útil?

Solución

In this case the reflection API may be useful:

for (int i = 0; i < 9; i++) {
        try {
            final Field field = KeyEvent.class.getDeclaredField("VK_" + i);
            r.keyPress((int) field.get(KeyEvent.class));

        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top