|
-
Jan 12th, 2006, 02:06 AM
#1
Thread Starter
New Member
How can ignore the specific key
such as start up key(keycode = 91) .
Thank you very much for every reply
-
Jan 12th, 2006, 02:59 AM
#2
Frenzied Member
Re: How can ignore the specific key
what is a start up key?
and what do you want to ignore the key, your program, the system?
-
Jan 12th, 2006, 03:48 AM
#3
Re: How can ignore the specific key
 Originally Posted by Sung007
such as start up key(keycode = 91) .
Thank you very much for every reply
If you mean the key with the windows logo, the key that brings up start menu,
it could also be fired pressing Ctrl- Esc.
About ingoring this sort of key, take a look Here
Many other common keys can be ignored like this:
VB Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc("a") Or KeyAscii = Asc("A") Then KeyAscii = 0
End Sub
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
-
Jan 12th, 2006, 03:59 AM
#4
Re: How can ignore the specific key
You can use a low-level keyboard hook to discard the Window key (doesn't work on Win9x/ME). Add the following code to a regular BAS module.
VB Code:
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 CallNextHookEx Lib "user32" ( _
ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
ByVal hHook As Long) As Long
Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" ( _
pDest As Any, _
pSource As Any, _
ByVal cb As Long)
Private Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Private Const HC_ACTION = 0&
Private Const WH_KEYBOARD_LL = 13&
Private Const VK_LWIN = &H5B&
Private Const VK_RWIN = &H5C&
Private hKeyb As Long
Private Function KeybCallback(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Static udtHook As KBDLLHOOKSTRUCT
If (Code = HC_ACTION) Then
'Copy the keyboard data out of the lParam (which is a pointer)
Call CopyMemory(udtHook, ByVal lParam, Len(udtHook))
Select Case udtHook.vkCode
Case VK_LWIN, VK_RWIN
KeybCallback = 1
Exit Function
End Select
End If
KeybCallback = CallNextHookEx(hKeyb, Code, wParam, lParam)
End Function
Public Sub HookKeyboard()
UnhookKeyboard
hKeyb = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeybCallback, App.hInstance, 0&)
End Sub
Public Sub UnhookKeyboard()
If hKeyb <> 0 Then
Call UnhookWindowsHookEx(hKeyb)
hKeyb = 0
End If
End Sub
In Form_Load call HookKeyboard and in Form_Unload call the UnhookKeyboard sub.
-
Jun 16th, 2012, 01:52 AM
#5
New Member
Re: How can ignore the specific key
 Originally Posted by Joacim Andersson
You can use a low-level keyboard hook to discard the Window key (doesn't work on Win9x/ME). Add the following code to a regular BAS module.
VB Code:
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 CallNextHookEx Lib "user32" ( _
ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
ByVal hHook As Long) As Long
Private Declare Sub CopyMemory _
Lib "kernel32" Alias "RtlMoveMemory" ( _
pDest As Any, _
pSource As Any, _
ByVal cb As Long)
Private Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Private Const HC_ACTION = 0&
Private Const WH_KEYBOARD_LL = 13&
Private Const VK_LWIN = &H5B&
Private Const VK_RWIN = &H5C&
Private hKeyb As Long
Private Function KeybCallback(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Static udtHook As KBDLLHOOKSTRUCT
If (Code = HC_ACTION) Then
'Copy the keyboard data out of the lParam (which is a pointer)
Call CopyMemory(udtHook, ByVal lParam, Len(udtHook))
Select Case udtHook.vkCode
Case VK_LWIN, VK_RWIN
KeybCallback = 1
Exit Function
End Select
End If
KeybCallback = CallNextHookEx(hKeyb, Code, wParam, lParam)
End Function
Public Sub HookKeyboard()
UnhookKeyboard
hKeyb = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeybCallback, App.hInstance, 0&)
End Sub
Public Sub UnhookKeyboard()
If hKeyb <> 0 Then
Call UnhookWindowsHookEx(hKeyb)
hKeyb = 0
End If
End Sub
In Form_Load call HookKeyboard and in Form_Unload call the UnhookKeyboard sub.
The AddressOf operator doesn't working.
Please resolve it.
Thank you.
-
Jun 16th, 2012, 05:35 AM
#6
Re: How can ignore the specific key
 Originally Posted by scsoumya
The AddressOf operator doesn't working.
Please resolve it.
Thank you.
Hi... Welcome to the forums 
Please note that you were replying to a 6 year old thread!
I just tested Joacim Andersson's code and it worked fine in my Windows XP machine.
If you got any issues while testing that code, then create a new thread in here specifying the details.
Also note that, this is VB6 code. So, you have to copy that code in a new Module in your project and inside a form, you need to call the subs HookKeyboard (to hook it) and UnhookKeyboard (unhooks)
Hope this helps.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|