该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
参考iteye上面的一篇文章测试的:http://yuebo85.iteye.com/blog/1392530
模拟键盘敲击abc...xyz 12345 空格 Alt 这些键位都正常,但是方向键不正常,请问是怎么回事儿
模拟键盘敲击a 正常
Thread.sleep(3000);
VirtualKeyBoard.KeyDown(VKMapping.toScanCode("a"));
Thread.sleep(100);
VirtualKeyBoard.KeyUp(VKMapping.toScanCode("a"));
模拟键盘敲击向左键 不正常,敲击的是4
Thread.sleep(3000);
VirtualKeyBoard.KeyDown(VKMapping.toScanCode("left"));
Thread.sleep(100);
VirtualKeyBoard.KeyUp(VKMapping.toScanCode("left"));
键位映射
map.put("Up", KeyEvent.VK_UP);
map.put("Dwon", KeyEvent.VK_DWON);
map.put("0", KeyEvent.VK_0);
map.put("1", KeyEvent.VK_1);
map.put("2", KeyEvent.VK_2);
map.put("3", KeyEvent.VK_3);
map.put("4", KeyEvent.VK_4);
map.put("5", KeyEvent.VK_5);
JNative调用部分
public class User32 extends org.xvolks.jnative.util.User32{
private static Map keycache=new HashMap();
public static int MapVirtualKeyA(int key) throws Exception{
if(!keycache.containsKey(key)){
JNative jnative=new JNative(DLL_NAME, "MapVirtualKeyA");
jnative.setRetVal(Type.INT);
jnative.setParameter(0, key);
jnative.setParameter(1, 0);
jnative.invoke();
int re=jnative.getRetValAsInt();
keycache.put(key, re);
}
return keycache.get(key);
}
}