他们真的是虚拟代码吗? [英] Are they really the virtual codes?

查看:175
本文介绍了他们真的是虚拟代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与C ++ / C相比,某些键(如 shift,[,],Del等)的虚拟键代码在Java中显示为不同的值。例如:

 键Java C / C ++ 
Shift 16 160
[91 219
] 93 221
\ 92 220
Del 127 46
窗口524 91


$ b b

原因是什么?这些代码是虚拟代码还是它们是不同类型?对于包括字母,数字的键,功能键(F1-F12),退格键,`等等是一样的。



我可能会误解一个概念,请澄清。



  KBDLLHOOKSTRUCT * kbhook =(KBDLLHOOKSTRUCT *)lParam; 
printf(%u\\\
,kbhook-> vkCode);

签入Java

  private void jTextField1KeyPressed(java.awt.event.KeyEvent evt){
int code = evt.getKeyCode();
// code isEqualTo KeyEvent.VK_DELETE:NOTE

}

参考: KeyEvent类

解决方案

虚拟键码非常虚拟,我应该说。



对于您要尝试互操作的每个平台,如果没有类似JavaKeyToWin32Key,Win32KeyToJava等代码,您将无法逃避。



我相信所有这些键代码大多是历史。一些来自硬件设计决策(看看苹果的现代键码,其中0码是'A',1是'S',2是'D'等等 - 我应该继续还是得到



这是商业活动没有什么个人的。三十四年前每个人从头开发自己的硬件,二十五年前每个人都在努力做最好的CPU,15年前,它已经开始与平台,一切都再次重新定义,但也应该保持与现有解决方案(当然由同一家公司)的兼容性。



Java是一个标准,但不是每个人。它已经是一个具有自己的键码集的所有操作系统之上的抽象。所以VK_是Microsoft的遗产,Java密钥代码可能受到Sun Solaris OS的影响,但我不确定。


Virtual key codes for some keys like shift, [ , ],Del etc are displayed as a different value in java compared to C++/C. For example :

Key     Java       C / C++
Shift   16         160
[       91         219
]       93         221
\       92         220
Del     127        46
Window  524        91

What is the reason for this ? Are these codes the virtual codes or they are a different type ? For the keys including alphabets,numbers,the function keys(F1-F12),backspace,`,etc are the same.

I might be misunderstanding a concept,in that case please clarify.

Checked in C/C++

KBDLLHOOKSTRUCT * kbhook = (KBDLLHOOKSTRUCT *) lParam;
printf("%u\n",kbhook->vkCode);

Checked in Java

private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {                                       
    int code = evt.getKeyCode();
    // code isEqualTo KeyEvent.VK_DELETE : NOTE

}

Ref : KeyEvent class

解决方案

Virtual Key Codes are extremely virtual, I should say.

You won't get away without some code like JavaKeyToWin32Key, Win32KeyToJava and so on for each platform you're trying to interoperate with.

I believe all of these keycodes are mostly historical. Some come from hardware design decisions (take a look at Apple's "modern" key codes where the 0 code is 'A', 1 is 'S', 2 is 'D' and so on - should I continue or you get the "pattern" which follows from the keyboard layout ?).

"Why there are no standard ?"

It's business and nothing personal. Thirty-forty years ago everyone where developing their own hardware from scratch, twenty five years ago everybody were trying to make the best CPU, 15 years ago it has all began with the "platforms", where everything was once again redefined, but also should maintain compatibility with existing solutions (by the same company, of course).

Java is a standard, but not for everyone. It is already an abstraction above all the OSes with its own set of keycodes. So "VK_" is a legacy of Microsoft, Java key codes might be influenced by the Sun Solaris OS, but I'm not sure.

这篇关于他们真的是虚拟代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆