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

有帮助吗?

解决方案

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();
        }
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top