Results 1 to 8 of 8

Thread: Enabling Disabled Keyboard/mouse

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    149
    Hi,
    Just wondering how to enable a keyboard & mouse after using
    Code:
    Private sub Command1_Click()
    
        Shell "rundll32 mouse,disable"
        Shell "rundll32 keyboard,disable"
    
    End Sub
    to disabel it.

    I am just writing a program and after a time (set by a timer) I would like to be able to re enable the mouse & keyboard after my program has disabled it.

    If you have any better way of doing this please let me know.



    Thanks

    Hurgh

  2. #2
    Guest
    Try this to enable it:

    Code:
    Private sub Command2_Click()
    
        Shell "rundll32 mouse,enable"
        Shell "rundll32 keyboard,enable"
    
    End Sub
    But I wonder how'd you re-enable it when you can't use the mouse or the keyboard because no events will get through. So, your other possibility would be to just restart the computer through code.

    Code:
    Declare Function ExitWindowsEx Lib "user32.dll" _
     (ByVal uFlags As Long, ByVal dwReserved As Long) As Long 
    
    EWX_FORCE = 4
    EWX_REBOOT = 2
    
    retval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
    If retval = 0 Then Debug.Print "Error:  Cannot shutdown!"
    Best bet would be to have a form popup telling the user, "Joke's over! Restarting..."

    Hope that helps.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    149

    Doesn't Work

    Sorry I should have put this in my original post,
    I have tried using
    Code:
    Private sub Command2_Click()
    
        Shell "rundll32 mouse,enable"
        Shell "rundll32 keyboard,enable"
    
    End Sub
    to enable it again but that did not work,

    And There is a way to enable it again if you cant use the keyboard and mouse, you just put the enable script in a timer and when you excute the disable code you also enable the timer.

    Also this program is not a joke or a virus or something bad, It is a sort of backup program and I have made another one but it does not disable mouse and keyboard and the users (people that I work with) have a habit of stoping it or making it stuff up some how so I want to disable the use of the keyboard and mouse system wide so that they can not do anything while the backup is i progress.

    Thanks

    Hurgh

  4. #4
    Guest
    Yeah, I just disabled and try re-enabling it and the hourglass came on and did nothing.

    Well, I guess you'd have to use the second option mentioned above, once you restart your computer, the mouse will be able to move freely and the keyboard will be able to type again.

  5. #5
    Guest
    I just though of another option. Lock the mouse on a form and disable all the buttons and stuff on your form.

    Code:
    Declare Function ClipCursor Lib "user32" (lpRect As _
     Any) As Long
    
    Type RECT
      Left As Long
      Top As Long
      Right As Long
      Bottom As Long
    End Type
    
    Public Sub DisableTrap(CurForm As Form)
    Dim erg As Long
    'Declare a variable for the procedure
    'to set the new coordinates
    Dim NewRect As RECT
    'Set the new coordinates to full screen
    With NewRect
      .Left = 0&
      .Top = 0&
      .Right = Screen.Width / Screen.TwipsPerPixelX
      .Bottom = Screen.Height / Screen.TwipsPerPixelY
    End With
    
    erg& = ClipCursor(NewRect)
    End Sub
    
    Public Sub EnableTrap(CurForm As Form)
    Dim X As Long, Y As Long, erg As Long
    'Declare a variable for the procedure
    'to set the new coordinates
    Dim NewRect As RECT
    'Get the TwipsperPixel
    'The Form's ScaleMode must be set to Twips!!!
    X& = Screen.TwipsPerPixelX
    Y& = Screen.TwipsPerPixelY
    'Set the Cursor-Region to the coordinates
    'of the form
    With NewRect
      .Left = CurForm.Left / X&
      .Top = CurForm.Top / Y&
      .Right = .Left + CurForm.Width / X&
      .Bottom = .Top + CurForm.Height / Y&
    End With
    erg& = ClipCursor(NewRect)
    End Sub
    
    'Enable - lock mouse
    EnableTrap Me
    
    'Disable - unlock mouse
    DisableTrap Me

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    149
    Two things,

    I dont want to shutdown the computer cause it is sort of a server, it has to stay on for 5 days of the week and needs to do a backup every day so I cant have it restarting every day.

    Also I would like to not just trap the mouse in a form and disable the buttons cause there is still room then for an error or something then the mouse is enabled again,
    I want to use the function rundll32 thing I just need to find out how to enable the stuff again.

    If there is an error in the app then I can decide if the error needs the keyboard to be re enabled or if it can wait till the backup has finished.

    Thanks

    Any other people know how to re enable the keyboard and mouse??

    Hurgh

  7. #7
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Another solution

    Actually its something I did a few years ago for the exact same reason as hurgh. In effect it is the same idea as Matthew's latest contribution to the thread.

    I made a screen saver that didn't save the screen. Sounds funny huh? All that it consisted of was a small password window which could be moved around etc. The rest of the screen was perfectly visible but of course could not see any mouse or keyboard events at all.

    In the company I was working at, the "no save screen saver" became very popular amongst staff who wished to go to appointments but leave their electronic diary set to display the days meetings etc. This way, a colleague coming to see the person could easily see when they would be back.

    The screen saver accepted the user's password and also a system password known only to the system admin staff. This meant that when we went to a user's machine to fix a fault or whatever, we could get in even if they were not there. Nowadays, Windows NT offers the same thing although "back then" it didn't.

    Yup, the no save screensaver was quite the technological breakthrough in it's time

    Perhaps you can do the same thing to solve your problem. As long as the password was not know to your pesky colleagues, then you can easily safegaurd your system while the backup runs.

    Regards
    Paul Lewis

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Australia
    Posts
    149
    Has anyone else got any sugestionson how I could do this??

    Thanks

    Hurgh

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