|
-
Aug 23rd, 2010, 07:12 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Monitor key down and disable "windows key" on keyboard
How can I disable the windows button on the keyboard while my application is focused?
I'm having an endless problem with users accidentally pressing the windows key on the keyboard which causes the application to lose focus. They are capturing data, so when they finally realize that while they were typing nothing happened. They have to find the place where they lost focus and redo everything from there. This is very time consuming and as we are paying our data capturers by the hour this turns out to be an expensive flaw in the application.
Can anyone please help me?
-
Aug 23rd, 2010, 08:20 AM
#2
Re: Monitor key down and disable "windows key" on keyboard
Just Google for a little program that you can run and do that with. Such programs are very popular with gamers who suffer from the same problem.
-
Aug 23rd, 2010, 08:55 AM
#3
Thread Starter
Addicted Member
Re: Monitor key down and disable "windows key" on keyboard
Yes, this would solve my problem, but then it disables the button on the whole pc. I dont want that. I only want it to be disabled while my application is running. And I'd rather code something like this into my software than use a separate application. This makes my application more "complete"
-
Aug 23rd, 2010, 10:15 AM
#4
Re: Monitor key down and disable "windows key" on keyboard
It can be done, but you need to use a low-level keyboard hook to intercept the pressing of the windows key. Here's one that I use for various things. It's not my code, but it's very easy to use:
WindowsHookLib.zip
Add it's controls to your toolbox by selecting the .dll file in the bin directory (or you can import the entire project, recompile it and attach it that way; it's also programmed in VB.NET). It has three hooks: One for the mouse, one for the keyboard and one for the clipboard. Drag a LLKeyboardHook component object onto your form.
Activate it and intercept the general, non-focused keyboard inputs according to the example below.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LlKeyboardHook1.InstallHook()
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
LlKeyboardHook1.RemoveHook()
End Sub
Private Sub LlKeyboardHook1_KeyDown(ByVal sender As Object, ByVal e As WindowsHookLib.KeyEventArgs) Handles LlKeyboardHook1.KeyDown
If e.KeyCode = Keys.LWin OrElse e.KeyCode = Keys.RWin Then
e.Handled = True
End If
End Sub
End Class
By saying that the keypress is "handled", you intercept it and tell Windows to stop any further processing of it.
Last edited by Jenner; Aug 24th, 2010 at 07:55 AM.
Tags for this Thread
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
|