VB.Net - 转换KeyCode [英] VB.Net - Convert KeyCode
问题描述
大家好我试图创建一个UI应用程序,在其上显示用户实际键入的内容以及将在应用程序窗口中显示的内容,就像桌面顶部的栏一样,键入的击键呈现并且将从右侧向左侧连续移动,就像在您看到的交换中一样。
我的问题是我使用GetAsyncKeyState()API函数和这个只代表Ascci Keycodes,与你输入像Here这样的文本框时不一样。
我想说的是它并没有真正识别键盘命令(Shift& a,哪个返回''a''而不是''A'')并且它不代表阿拉伯语和西里尔语或中文等键盘语言。
甚至可以自动化一个应用程序来做更少的代码吗?
我的例子;
Hi people im trying to create an UI Application on which is shown what the User actually types and which will be shown on the Window of the Application, to say like a Bar on the top of the Desktop, on which the typed Keystrokes are presented and which will continuosly move from right to the left side, like in a Exchange you see.
My problem is i use the GetAsyncKeyState() API Function and this only represents the Ascci Keycodes and not the same as when you type in Textbox like "Here".
What i want to say is that it doesnt really recognize what the Keyboard commands(Shift & a, which returns ''a'' but not ''A'') and also it doesnt represent the Keyboard Languages like Arabic and Cyrillic or Chinese.
Is it even possible to automate an App to do this which less code?
My Example;
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vkey As Integer) As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim Result as integer
For i = 1 to 255
Result = GetAsyncKeyState(i)
If Result = -32767 then
textbox1.text = Cstr(chr(i))
End If
Next
End Sub
你能给我一个提示,在哪里寻找解决方案,还是我还没有意识到的一些简单的事情?
Can you give me a tip where to search for the solution or is it something easy which i didnt yet realise?
推荐答案
请仔细阅读: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293%28v=vs.85%29.aspx [ ^ ]。
此API适用于虚拟键,例如.NETSystem.Windows.Forms.KeyCode
。这些密钥代码不是扫描代码,而不是ASCII或Unicode UTF的字符代码。
基本上,键盘的处理方式如下:扫描代码 - >虚拟键 - >非字符键的字符(包括删除)或非字符事件(例如KeyUp
,KeyDown
)。< br $> b $ b
请同时查看.NET键盘事件(无论是System.Windows.Forms
还是WPF)并进行比较使用Windows API信息传递给事件处理程序的数据。它应该可以帮助您了解您的确在做什么。例如,我不明白你想要实现的目标。机会是,纯.NET FCL可以帮助你更多。请记住,P / Invoke可以破坏平台兼容性,因此纯.NET总是更好。我承认在某些情况下使用原始Windows API是不可避免的,但这种情况相对较少。如果你解释了你的目标,你就有机会获得更多建议。
-SA
Please see more thoroughly: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293%28v=vs.85%29.aspx[^].
This API works with virtual keys, same as, for example, .NETSystem.Windows.Forms.KeyCode
. Those key codes are not scan codes, and not character codes as ASCII or Unicode UTFs.
Basically, the keyboard is processed like this: scan code -> virtual keys -> characters (including delete) or non-character events (such asKeyUp
,KeyDown
for non-character keys).
Please also look at .NET keyboard events (no matter,System.Windows.Forms
or WPF) and compare the data passed to event handlers with Windows API information. It should help you to understand what you are really doing. I, for example, don''t understand what you are trying to achieve. Chances are, pure .NET FCL could help you more. Remember that P/Invoke can kill platform compatibility, so pure .NET is always better. I admit there are certain cases when using raw Windows API is unavoidable, but such cases are relatively rare. If you explain your goal, you can get a chance to receive some more advice.
—SA
这篇关于VB.Net - 转换KeyCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!