Results 1 to 18 of 18

Thread: [RESOLVED] How to disable mouse and keyboard for 10 seconds

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2020
    Posts
    48

    Resolved [RESOLVED] How to disable mouse and keyboard for 10 seconds

    Hi,
    I'm working on a splash screen which lasts about 10 seconds. I want to disable mouse and keyboard functions during this time (splash screen) and define a hotkey of Alt+Ctrl+2 to force the splash screen to stop (this hotkey is just used for killing the process).
    What code in the windows form section can handle this task?
    Attached Files Attached Files
    Last edited by fa2020; Jul 30th, 2020 at 10:31 PM.

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,837

    Re: How to disable mouse and keyboard for 10 seconds

    If you do a Google search on:

    vb .net disable mouse and keyboard function

    You will get pages of results with examples. And then wrap the example around a timer or when the splash screen unloads.

    Save us some typing
    Please remember next time...elections matter!

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: How to disable mouse and keyboard for 10 seconds

    Quote Originally Posted by fa2020 View Post
    Hi,
    I'm working on a splash screen which lasts about 10 seconds. I want to disable mouse and keyboard functions during this time (splash screen) and define a hotkey of Alt+Ctrl+2 to force the splash screen to stop (this hotkey is just used for killing the process).
    What code in the windows form section can handle this task?
    https://stackoverflow.com/questions/...vb-net-program?

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2020
    Posts
    48

    Re: How to disable mouse and keyboard for 10 seconds

    Unfortunately, I couldn't find any code for disabling mouse and keyboard globally.
    Can anyone please guide me?

  5. #5
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: How to disable mouse and keyboard for 10 seconds

    if you want to define a hotkey (Alt+Ctrl+2), it is not a good idea to disable the keyboard...

    you can use BlockInput : https://docs.microsoft.com/en-us/win...ser-blockinput

    Code:
    Declare Function BlockInput Lib "User32" (ByVal fBlockIt As Boolean) As Boolean
    
    
    use in code : BlockInput(True)
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: How to disable mouse and keyboard for 10 seconds

    Quote Originally Posted by Delaney View Post
    if you want to define a hotkey (Alt+Ctrl+2), it is not a good idea to disable the keyboard...

    you can use BlockInput : https://docs.microsoft.com/en-us/win...ser-blockinput

    Code:
    Declare Function BlockInput Lib "User32" (ByVal fBlockIt As Boolean) As Boolean
    
    
    use in code : BlockInput(True)
    I don't remember the key combination, but there is a hotkey that ends BlockInput

  7. #7
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: How to disable mouse and keyboard for 10 seconds

    Quote Originally Posted by fa2020 View Post
    Unfortunately, I couldn't find any code for disabling mouse and keyboard globally.
    Can anyone please guide me?
    That is probably because disabling the mouse and keyboard globally is a bad idea anyway, I would certainly be wary of running any application that disable mouse and keyboard to my entire system.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: How to disable mouse and keyboard for 10 seconds

    Why would you want to do this? Clearly, there's a problem, since you have a hotkey combination that won't work if the keyboard is disabled. Also, you guarantee that everybody will hate your program. I have two monitors on one computer and three on another. Do I really want a program that will stop me from doing anything on any monitor while it loads? No, I really do not.

    So, aside from pissing off any users, what are you trying to prevent with this?
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2020
    Posts
    48

    Re: How to disable mouse and keyboard for 10 seconds

    I provided a test of my program. I used Visual Studio wallpaper as form background just for test. I wrote the code you provided for disabling mouse and keyboard globally, but nothing happens. Please look at VS 2019 file which I uploaded above.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: How to disable mouse and keyboard for 10 seconds

    It doesn't disable anything globally. Just your app.

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2020
    Posts
    48

    Re: How to disable mouse and keyboard for 10 seconds

    But, I can still hover my mouse over the splash screen when I run it. Please have a look on my example file.
    My goal is to disable Task Manager from killing the app. I want to disable Ctrl+Alt+Del function and not allow task manager to kill my app.
    Last edited by fa2020; Jul 31st, 2020 at 12:11 AM.

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: How to disable mouse and keyboard for 10 seconds

    Mousemove isn't user input. Your goal is not something we can or would help with. It could be used maliciously...

  13. #13
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: How to disable mouse and keyboard for 10 seconds

    Quote Originally Posted by .paul. View Post
    I don't remember the key combination, but there is a hotkey that ends BlockInput
    Yes Ctrl+Alt+Del unblocks
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  14. #14

    Thread Starter
    Member
    Join Date
    Jun 2020
    Posts
    48

    Re: How to disable mouse and keyboard for 10 seconds

    Quote Originally Posted by .paul. View Post
    Mousemove isn't user input. Your goal is not something we can or would help with. It could be used maliciously...
    But, I just want to learn something. I'm in the first steps of VB.NET programming. I don't want to bother anyone.

  15. #15
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: How to disable mouse and keyboard for 10 seconds

    Quote Originally Posted by .paul. View Post
    Mousemove isn't user input. Your goal is not something we can or would help with. It could be used maliciously...
    It reminds me that's a few weeks ago we had exactly that at work. On of my colleague had a trouble with a subcontractor web page that pops up a false web page windows alert (you know the one with a nice phone number ) and blocked the keyboard and the mouse click . We manage to unblock the situation by unpluging the keyboard and repluging it... (by the way we had to warn the subcontractor that its web page has been infected)
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  16. #16
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: How to disable mouse and keyboard for 10 seconds

    Quote Originally Posted by fa2020 View Post
    But, I just want to learn something. I'm in the first steps of VB.NET programming. I don't want to bother anyone.
    Interesting, my first steps into VB.net had been programming games...
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: How to disable mouse and keyboard for 10 seconds

    Quote Originally Posted by fa2020 View Post
    But, I just want to learn something. I'm in the first steps of VB.NET programming. I don't want to bother anyone.
    Then try learning something useful instead. We all had to learn and I feel fairly safe in saying that none us did this.

  18. #18
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,902

    Re: [RESOLVED] How to disable mouse and keyboard for 10 seconds

    Agree with the above. What you're asking to do is basically a violation of best practice for apps and would be wide open to abuse. Microsoft have gone out of there way to make sure you can't do what you're suggesting doing.

    Why do you want to prevent your app from being closed while the splash screen is opening? There may be a better way of achieving your goal.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

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