Results 1 to 7 of 7

Thread: [RESOLVED] [2005] Disable mouse and keyboard input?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    97

    Resolved [RESOLVED] [2005] Disable mouse and keyboard input?

    Is there a way I can do this easily? I have a main form loading with 3 check boxes that the user can choose, mouse input , keyboard input or both. Instead of loading 3 seperate forms is there a way I can just disable input from mouse if they choose keyboard only or disable keyboard if they choose mouse.. or do I have to make each form seperate? Thanks for advice.

  2. #2
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2005] Disable mouse and keyboard input?

    Here try using booleans the code i will show will just give an example of how to do it so you cna figure the rest urself.

    vb Code:
    1. Public Class Form1
    2.     Dim keyboard_used As Boolean = False
    3.     Dim mouse_used As Boolean = False
    4.     Private Sub Button1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyUp
    5.        
    6. If e.KeyCode = Keys.Enter Then
    7.             keyboard_used = True
    8.             mouse_used = False
    9.         End If
    10.     End Sub
    11.  
    12.    
    13.     Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
    14.         If e.Button = Windows.Forms.MouseButtons.Left Then
    15.             keyboard_used = False
    16.             mouse_used = True
    17.         End If
    18.     End Sub
    19.  
    20.  
    21. End Class

  3. #3
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2005] Disable mouse and keyboard input?

    Thats an example with buttons now change the buttons to checkboxes and make the actions code only work when one of the booleans = true or something like that.

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2005] Disable mouse and keyboard input?

    I'm confused. Why would you want to disable one or the other? If you can have both then why can't people just use the one(s) they want?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: [2005] Disable mouse and keyboard input?

    Oh ya PlanetX what is the point is there a specfic reason because then maybe there is another set of code that can be used or another solution.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    97

    Re: [2005] Disable mouse and keyboard input?

    sorry this is a mastermind game assignment and i need to have a menu at the start for letting the user choose keyboard or mouse input, or both. I haven't had a chance to look at the code yet to see if I can get it working but I will as soon as I'm off work. Thanks for the advice , appreciate it. Maybe there is an easier way and I am not aware of.

  7. #7
    Hyperactive Member cameron2's Avatar
    Join Date
    Mar 2008
    Location
    Australia
    Posts
    401

    Re: [2005] Disable mouse and keyboard input?

    This could be a start:

    Add 3 checkboxes: Disablemouse, Disablekeyboard and Disableboth
    Code:
    Public Class Form1
        Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
    
        Private Sub Disableboth_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Disableboth.CheckedChanged
            If Disableboth.Checked = True Then
                BlockInput(True)
                Threading.Thread.Sleep(1000) 'blocks for 1 second
                BlockInput(False)
            End If
    
        End Sub
    End Class
    As you can see i only know a way to block both keyboard AND mouse until Crt + Alt + Del is pressed.

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