EDN Admin
Well-known member
Ive found several topics similar to, but not quite what I need. Im merely trying to disable (or just redirect) the left Windows key while a certain program is open and has focus.
For instance, lets say I want to disable the left Windows key while Notepad is open, what do I need to do? Im using Visual Basic 2010 and let it be known Im am pretty strong on the Basic language itself, but Im pretty new to .NET. I program as a hobby
and usually just simple utilities for my own personal use only so be sure to write it a little bit dumbed down, but not too much.
I was experimenting with this code:
<pre class="prettyprint lang-vb Public Class Form1
Private Const KEYEVENTF_EXTENDEDKEY As Long = &H1
Private Const KEYEVENTF_KEYUP As Long = &H2
Private Const VK_LWIN As Byte = &H5B
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.LWin Then keybd_event(Keys.LControlKey, 0, KEYEVENTF_EXTENDEDKEY, 0)
End Sub
End Class[/code]
<br/>
and it actually seems to work, except for two problems. First, I get a "PInvokeStackImbalance was detected" error as soon as I press the left Windows key, but the key *IS* intercepted because the Start Menu doesnt open. The second issue is that the Left
Control Key is then set in a permanent "key down" state until I press the key manually which resets it.
Anyhow, my basic question still remains. How do I disable the left Windows key while a particular window has focus.
Thanks guys.
View the full article
For instance, lets say I want to disable the left Windows key while Notepad is open, what do I need to do? Im using Visual Basic 2010 and let it be known Im am pretty strong on the Basic language itself, but Im pretty new to .NET. I program as a hobby
and usually just simple utilities for my own personal use only so be sure to write it a little bit dumbed down, but not too much.
I was experimenting with this code:
<pre class="prettyprint lang-vb Public Class Form1
Private Const KEYEVENTF_EXTENDEDKEY As Long = &H1
Private Const KEYEVENTF_KEYUP As Long = &H2
Private Const VK_LWIN As Byte = &H5B
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.LWin Then keybd_event(Keys.LControlKey, 0, KEYEVENTF_EXTENDEDKEY, 0)
End Sub
End Class[/code]
<br/>
and it actually seems to work, except for two problems. First, I get a "PInvokeStackImbalance was detected" error as soon as I press the left Windows key, but the key *IS* intercepted because the Start Menu doesnt open. The second issue is that the Left
Control Key is then set in a permanent "key down" state until I press the key manually which resets it.
Anyhow, my basic question still remains. How do I disable the left Windows key while a particular window has focus.
Thanks guys.
View the full article