Results 1 to 5 of 5
  1. #1

    Default [vb] handling keystrokes


    there are sample codes to handle/disable keystrokes/keystrokes combination ctrl-alt-del, alt+tab but none for WINDOW key. anyone know how to disable WINDOW key?

  2. #2

    Default Re: [vb] handling keystrokes

    pag create ug .bas with these codes

    Option Explicit

    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long

    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

    Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long,ByVal lParam As Long) As Long

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal cb As Long)

    Private Const WH_KEYBOARD_LL = 13&
    Private Const HC_ACTION = 0&
    Public Const VK_LWINKEY = &H5B
    Public Const VK_RWINKEY = &H5C

    Private lKBDhook As Long
    Private bHookEnabled As Boolean

    Private Type KBDHOOKSTRUCT
    vkCode As Long
    scanCode As Long
    flags As Long
    Time As Long
    dwExtraInfo As Long
    End Type

    Private o_KBDhook As KBDHOOKSTRUCT

    Public Function KBDhookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    If nCode = HC_ACTION Then
    Call CopyMemory(o_KBDhook, ByVal lParam, Len(o_KBDhook))
    If (o_KBDhook.vkCode = VK_LWINKEY) And (o_KBDhook.flags = 1) Then
    Debug.Print "You pressed the left Windows key. Normally the Start Menu would appear..."
    KBDhookProc = 1
    Exit Function
    End If

    If (o_KBDhook.vkCode = VK_RWINKEY) And (o_KBDhook.flags = 1) Then
    Debug.Print "You pressed the right Windows key. Normally the Start Menu would appear..."
    KBDhookProc = 1
    Exit Function
    End If

    End If

    KBDhookProc = CallNextHookEx(lKBDhook, nCode, wParam, lParam)
    End Function


    Public Function SetHook()

    If lKBDhook = 0 Then
    lKBDhook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KBDhookProc, App.hInstance, 0&)
    End If

    If lKBDhook = 0 Then
    MsgBox "Failed to install Keyboard Hook"
    bHookEnabled = False
    Exit Function Else
    bHookEnabled = True
    End If

    End Function


    Public Function UnSetHook()
    If bHookEnabled Then
    Call UnhookWindowsHookEx(lKBDhook)
    End If

    bHookEnabled = False

    End Function

    unsaon pag gamit

    (Form_Load or Sub Main): Call SetHook

    (Form_Unload or cleanup sub): Call UnSetHook

  3. #3

    Default Re: [vb] handling keystrokes

    it work.. but when i call UNSETHOOK and call SETHOOK the 2nd time it not longer handle window key stroke....Â*

    btw, do made d code alone?

  4. #4

    Default Re: [vb] handling keystrokes

    Quote Originally Posted by hybrid_X
    it work.. but when i call UNSETHOOK and call SETHOOK the 2nd time it not longer handle window key stroke....Â*

    btw, do made d code alone?
    nope... got that code from somewhere.. nalimot ko.. gi embed lang nako ato gibuhat naku b4..

  5. #5

    Default Re: [vb] handling keystrokes

    ayt man tnx

  6.    Advertisement

Similar Threads

 
  1. Replies: 289
    Last Post: 11-10-2017, 10:48 PM
  2. Error handling/trapping in vb using ibm database
    By skeptic_rob in forum Programming
    Replies: 7
    Last Post: 08-24-2010, 05:31 PM
  3. how would i handle this?
    By werty in forum "Love is..."
    Replies: 46
    Last Post: 04-05-2007, 04:58 AM
  4. having two jobs.. how do you handle it?
    By AlecZander in forum Business, Finance & Economics Discussions
    Replies: 18
    Last Post: 06-15-2006, 02:08 PM
  5. Replies: 29
    Last Post: 10-09-2005, 12:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top