Click here to Skip to main content
15,888,351 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionDisabling the keyboard Pin
Pasan14811-Feb-11 7:17
Pasan14811-Feb-11 7:17 
AnswerRe: Disabling the keyboard Pin
Dave Kreskowiak11-Feb-11 9:13
mveDave Kreskowiak11-Feb-11 9:13 
GeneralRe: Disabling the keyboard Pin
Pasan14812-Feb-11 3:26
Pasan14812-Feb-11 3:26 
GeneralRe: Disabling the keyboard Pin
Dave Kreskowiak12-Feb-11 3:53
mveDave Kreskowiak12-Feb-11 3:53 
GeneralRe: Disabling the keyboard Pin
Pasan14812-Feb-11 6:09
Pasan14812-Feb-11 6:09 
AnswerRe: Disabling the keyboard Pin
Luc Pattyn12-Feb-11 6:16
sitebuilderLuc Pattyn12-Feb-11 6:16 
GeneralRe: Disabling the keyboard Pin
Dave Kreskowiak12-Feb-11 16:43
mveDave Kreskowiak12-Feb-11 16:43 
GeneralRe: Disabling the keyboard Pin
Pasan14814-Feb-11 9:34
Pasan14814-Feb-11 9:34 
I used following code to implement my project as you suggest

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()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        hookID = SetHook(proc)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
        UnhookWindowsHookEx(hookID)
    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


But there is a problem in this function

Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
       
        If nCode Then
            Dim vkCode As Integer = Marshal.ReadInt32(lParam)
            If vkCode = Keys.A Then
                SendKeys.Send("B")
                Return CType(1, IntPtr)
            End If
        End If
         Return CallNextHookEx(hookID, nCode, wParam, lParam)
    End Function


If someone press 'A', I want to display 'B'. But according to this function it displays 'B' twice. How can I overcome this problem.
GeneralRe: Disabling the keyboard Pin
Dave Kreskowiak14-Feb-11 13:57
mveDave Kreskowiak14-Feb-11 13:57 
GeneralRe: Disabling the keyboard Pin
Pasan14814-Feb-11 21:15
Pasan14814-Feb-11 21:15 
GeneralRe: Disabling the keyboard Pin
Dave Kreskowiak15-Feb-11 2:08
mveDave Kreskowiak15-Feb-11 2:08 
AnswerRe: Disabling the keyboard Pin
Eddy Vluggen11-Feb-11 10:08
professionalEddy Vluggen11-Feb-11 10:08 
AnswerRe: Disabling the keyboard Pin
Bernhard Hiller13-Feb-11 20:44
Bernhard Hiller13-Feb-11 20:44 
Questioncount character frequency Pin
Cool Smith11-Feb-11 3:24
Cool Smith11-Feb-11 3:24 
AnswerRe: count character frequency Pin
Tieske811-Feb-11 4:18
professionalTieske811-Feb-11 4:18 
GeneralRe: count character frequency Pin
Cool Smith11-Feb-11 4:31
Cool Smith11-Feb-11 4:31 
GeneralRe: count character frequency Pin
Tieske811-Feb-11 6:02
professionalTieske811-Feb-11 6:02 
GeneralRe: count character frequency Pin
Dave Kreskowiak11-Feb-11 6:17
mveDave Kreskowiak11-Feb-11 6:17 
AnswerRe: count character frequency Pin
Eddy Vluggen11-Feb-11 10:20
professionalEddy Vluggen11-Feb-11 10:20 
GeneralRe: count character frequency Pin
Cool Smith11-Feb-11 22:19
Cool Smith11-Feb-11 22:19 
GeneralRe: count character frequency Pin
Eddy Vluggen11-Feb-11 23:48
professionalEddy Vluggen11-Feb-11 23:48 
GeneralRe: count character frequency Pin
Cool Smith12-Feb-11 0:42
Cool Smith12-Feb-11 0:42 
GeneralRe: count character frequency Pin
Cool Smith12-Feb-11 4:00
Cool Smith12-Feb-11 4:00 
GeneralRe: count character frequency Pin
Eddy Vluggen12-Feb-11 5:43
professionalEddy Vluggen12-Feb-11 5:43 
QuestionStoring Binary Data in SQL Database with VB.NET Pin
Central_IT10-Feb-11 3:31
Central_IT10-Feb-11 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.