You must Sign In to post a response.
  • Category: Visual Studio

    Keyboard keys remapping using

    Imports System.Runtime.InteropServices
    Public Class Form1
    Private Const WH_KEYBOARD_LL As Integer = 13
    Private Const WM_KEYUP As Integer = &H101
    Private Const WM_SYSKEYUP As Integer = &H105
    Private proc As LowLevelKeyboardProcDelegate = AddressOf HookCallback
    Private hookID As IntPtr
    Private Delegate Function LowLevelKeyboardProcDelegate(ByVal nCode As Integer, ByVal wParam As IntPtr, _
    ByVal lParam As IntPtr) As IntPtr

    <DllImport("user32")> _
    Private Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal lpfn As LowLevelKeyboardProcDelegate, _
    ByVal hMod As IntPtr, ByVal dwThreadId As UInteger) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function UnhookWindowsHookEx(ByVal hhk As IntPtr) As <marshalas(unmanagedtype.bool)> Boolean
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function CallNextHookEx(ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, _
    ByVal lParam As IntPtr) As IntPtr
    End Function

    <DllImport("kernel32.dll", CharSet:=CharSet.Unicode)> _
    Private Shared Function GetModuleHandle(ByVal lpModuleName As String) As IntPtr
    End Function

    Sub New()
    Text = "KeyboardPlus 1.01"
    hookID = SetHook(proc)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
    End Sub

    Private Function SetHook(ByVal proc As LowLevelKeyboardProcDelegate) As IntPtr
    Using curProcess As Process = Process.GetCurrentProcess()
    Using curModule As ProcessModule = curProcess.MainModule

    Return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0)

    End Using
    End Using
    End Function

    Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    ' "The WM_KEYUP message is posted to the window with the keyboard focus
    ' when a nonsystem key is released. A nonsystem key is a key that is pressed when the ALT key is not pressed,
    ' or a keyboard key that is pressed when a window has the keyboard focus."

    If nCode >= 0 AndAlso (wParam.ToInt32 = WM_KEYUP OrElse wParam.ToInt32 = WM_SYSKEYUP) Then
    Dim vkCode As Integer = Marshal.ReadInt32(lParam)
    'vkCode = Keys.B
    If vkCode = Keys.A Then
    If Console.CapsLock = True Then
    'vkCode = Keys.B
    'vkCode = Keys.B
    End If

    End If
    End If
    Return CallNextHookEx(hookID, nCode, wParam, lParam)
    End Function

    End Class

    this code display output any application press a but print ab
  • #763923

    What is your issue?

    Can you share in your issue elaborate then I can easily solve in your issue.

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #763936
    elaborate your issue so that we can help you better in order to resolve the problem
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

Sign In to post your comments