Results 1 to 4 of 4

Thread: [RESOLVED] Monitor key down and disable "windows key" on keyboard

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Resolved [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?

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    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"

  4. #4
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

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
  •  



Click Here to Expand Forum to Full Width