需要您有关键盘重新映射的紧急帮助 [英] Need you urgent help regarding keyboard remapping
问题描述
您好,我正在尝试制作一个需要重新映射键盘的应用程序(在VB 2008中).例如,当我按下"A"时,它应该产生字符Æ",而当我按下"shift + A"时,它应该产生字符Ā".而且它应该是系统范围内的,即任何具有焦点的窗口以及此应用程序是否具有焦点.我希望我已经说清楚了.如果您能抽出宝贵的时间解决此问题,将非常高兴.我将热切等待您的答复.提前谢谢.
问候
电子邮件:[已删除]
[更新:回答问题时不要添加答案".将信息放在这里]
//@ Kristian Sixhoej:我正在使用以下代码将"a"重新映射为"b",但它会产生"ab".另外,如果我想重新映射"shift + a",我也不知道该怎么办.请调查一下,并告诉我我做错了什么.
另外@ AnnieMacD:我总是很难遵循Microsoft的文章.听起来太技术性了.
Hi, I am trying to make an application (in VB 2008) that requires me to remap the keyboard. For example, when I press "A" it should produce the character "Æ" and when I press "shift + A" it should produce the character "Ā". Also it should be system wide i.e. to any windows that has focus and whether or not this application has focus. I hope I have made myself clear. It will be so kind of you if you will take the time to solve this problem. I will be eagerly waiting for your response. Thanks in advance.
Regards
email : [removed]
[Update: do not add an "answer" when responding to questions. Put the information here]
@ Kristian Sixhoej: I am using the following code to remap "a" to "b" but it produces "ab". Also I could not figure out what to do if I want to remap "shift+a". Please look into it and tell me what I am not doing right.
Also @ AnnieMacD : I always find it difficult to follow microsoft articles. They sound too technical.
Option Strict On
Imports System.Runtime.InteropServices
Public Class Form1
Private Const KEYEVENTF_EXTENDEDKEY As Long = &H1
Private Const KEYEVENTF_KEYUP As Long = &H2
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const WH_KEYBOARD_LL As Integer = 13
Private Const WM_KEYUP As Integer = &H101
Private Shared _proc As LowLevelKeyboardProc = AddressOf HookCallback
Private Shared _hookID As IntPtr = IntPtr.Zero
Public Declare Auto Function SetWindowsHookEx Lib "user32.dll" ( _
ByVal idHook As Integer, ByVal lpfn As LowLevelKeyboardProc, _
ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr
Public Declare Auto Function UnhookWindowsHookEx _
Lib "user32.dll" (ByVal hhk As IntPtr) As IntPtr
Public Declare Auto Function CallNextHookEx _
Lib "user32.dll" (ByVal hhk As IntPtr, ByVal nCode As Integer, _
ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
Public Declare Auto Function GetModuleHandle Lib "kernel32.dll" ( _
ByVal lpModuleName As String) As IntPtr
Private Shared Function SetHook(ByVal proc As LowLevelKeyboardProc) As IntPtr
Dim curProcess As Process = Process.GetCurrentProcess()
Dim curModule As ProcessModule = curProcess.MainModule
Return SetWindowsHookEx(WH_KEYBOARD_LL, proc, _
GetModuleHandle(curModule.ModuleName), 0)
End Function
Public Delegate Function LowLevelKeyboardProc( _
ByVal nCode As Integer, ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As IntPtr
Public Shared Function HookCallback( _
ByVal nCode As Integer, _
ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
If nCode >= 0 And wParam = CType(WM_KEYUP, IntPtr) Then
Dim vkCode As Keys = CType(Marshal.ReadInt32(lParam), Keys)
If vkCode = Keys.A Or vkCode = Keys.A Then
keybd_event(CByte(Keys.B), 0, KEYEVENTF_EXTENDEDKEY, 0)
End If
End If
Return CallNextHookEx(_hookID, nCode, wParam, lParam)
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
_hookID = SetHook(_proc)
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
UnhookWindowsHookEx(_hookID)
End Sub
推荐答案
尝试一下:
http://msdn.microsoft.com/en-us/library/ms646318.aspx [ ^ ]
Try this:
http://msdn.microsoft.com/en-us/library/ms646318.aspx[^]
这篇关于需要您有关键盘重新映射的紧急帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!