Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Disable/enable keyboard and mouse input OS-wide with a key combination



Permlink Replies: 20 - Last Post: Dec 12, 2017 4:14 PM Last Post By: Adem Meda
Adem Meda

Posts: 495
Registered: 12/28/98
Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2017 8:05 PM
I am looking for a way to disable/enable input (from keyboard and mouse) and I
need it to work OS-wide.

I am hoping there already exists such a utility and someone who knows of one
will let me have a link to it.

Failing that, I'd like to write one --using Delphi, and that's where this NG
comes in.

Trouble is, I have never done such a thing; so I need the information how to.

BTW, I am aware that this may sound like on odd thing to ask for, but I have to
find a way to prevent our cats from causing havoc with my PC (and/or laptop) by
randomly pressing a key here and moving the mouse there..
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 10, 2017 11:42 PM   in response to: Adem Meda in response to: Adem Meda
Adem

Waht about just using a screensaver with a password. Evan a simple password should defeat the "paddy paws" method of typing

Roy Lambert

Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 1:20 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:

Roy,

Waht about just using a screensaver with a password. Evan a simple password
should defeat the "paddy paws" method of typing

It is a little more complicated, I am afraid.

Using screensaver is self-defeating in the cases when I (need to /want to)
watch movies and/or clips or read long articles.
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 5:52 AM   in response to: Adem Meda in response to: Adem Meda
Adem

Watching movies I can understand but reading long articles with the keyboard locked - hmmm <G>

Roy Lambert

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 7:57 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:
Adem

Watching movies I can understand but reading long articles with the keyboard locked - hmmm <G>


He means that the screensaver may appear while he reads a long article or he watches a movie
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 7:57 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:

Roy,

Watching movies I can understand but reading long articles with the keyboard
locked - hmmm <G>

Yes, it does sound a bit odd, doesn't it; but, sometimes I receive long (and
utterly boring) reports (PDF) that I need to read and take notes (on paper)
before I respond.
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 8:21 AM   in response to: Adem Meda in response to: Adem Meda
Adem

I was just wondering how you were going to scroll a "long" article with the keyboard and mouse locked.

Roy Lambert

Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 8:39 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:

Roy,

I was just wondering how you were going to scroll a "long" article with the
keyboard and mouse locked.

The kind of articles/reports I get takes more than 10 minutes per page to
read/study. They are so boring that I usually take another 10-minute break half
way --if I am not fast asleep by then.

You're a lucky man if you've never suffered such torture. :)
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 11:48 PM   in response to: Adem Meda in response to: Adem Meda
Adem

I was just wondering how you were going to scroll a "long" article with the
keyboard and mouse locked.

The kind of articles/reports I get takes more than 10 minutes per page to
read/study. They are so boring that I usually take another 10-minute break half
way --if I am not fast asleep by then.

You're a lucky man if you've never suffered such torture. :)

I do suffer from insomnia and my supply of sleep aids isn't working any more - can you share a few?

Roy
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 3:01 AM   in response to: Roy Lambert in response to: Roy Lambert
Roy Lambert wrote:

Roy,

I do suffer from insomnia and my supply of sleep aids isn't working any more
- can you share a few?

I can't share the ones I receive, but here is one that's close enough (except
that it includes some charts and other visuals).

http://investor.apple.com/secfiling.cfm?filingid=1628280-16-20309

Should give you some idea.
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 5:01 AM   in response to: Adem Meda in response to: Adem Meda
Adem Meda wrote:
I am looking for a way to disable/enable input (from keyboard and mouse) and I
need it to work OS-wide.

This task can be done using low level keyboard and mouse hooks.
https://msdn.microsoft.com/es-es/library/windows/desktop/ms644985(v=vs.85).aspx
https://msdn.microsoft.com/es-es/library/windows/desktop/ms644986(v=vs.85).aspx

I have uploaded a Delphi project to the attachment group which does what you ask:
https://forums.embarcadero.com/thread.jspa?threadID=271502

Build and run the application. Then:
Press the "LOCK" button from the main form to lock both the keyboard and the mouse.
Press Ctrl + Alt + F10 to unlock them.
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 7:57 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:

Antonio,

This task can be done using low level keyboard and mouse hooks.

I have uploaded a Delphi project to the attachment group which does what you
ask: https://forums.embarcadero.com/thread.jspa?threadID=271502

You have solved my problem.

Thank you so very much.

One question:

I had asked the same question in the Lenovo forums, but didn't get a solution.
Do you mind if I place the compiled code in some public place (sourceforge?) so
that people in similar situation can use it. If so, what copyright information
should I put on it (obviously, I will have no copyright because I didn't write
the code).

Or, alternatively, would you you make it available to the public and let me/us
have link.

And, yes, it is a very useful gem.

Thank you again.
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 10:12 AM   in response to: Adem Meda in response to: Adem Meda
El 11/12/2017 a las 16:57, Adem Meda escribió:
Antonio Estevez wrote:

Antonio,

This task can be done using low level keyboard and mouse hooks.

I have uploaded a Delphi project to the attachment group which does what you
ask: https://forums.embarcadero.com/thread.jspa?threadID=271502

You have solved my problem.

Thank you so very much.

One question:

I had asked the same question in the Lenovo forums, but didn't get a solution.
Do you mind if I place the compiled code in some public place (sourceforge?) so
that people in similar situation can use it. If so, what copyright information
should I put on it (obviously, I will have no copyright because I didn't write
the code).

Or, alternatively, would you you make it available to the public and let me/us
have link.

And, yes, it is a very useful gem.

Thank you again.

The code is public so feel free to do what you want with it.
If you publish the binary executable I ask you to include the project
files so that other people can adapt it to their needs.
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 10:26 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:

If you publish the binary executable I ask you to include the project
files so that other people can adapt it to their needs.

Was thinking of doing just that. And, will do so.

Thanks again.
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 4:14 PM   in response to: Adem Meda in response to: Adem Meda
Adem Meda wrote:

Was thinking of doing just that. And, will do so.

I have uploaded the source code (also x86 + x64 binaries) to the attchments NG.

nntp://forums.embarcadero.com/embarcadero.public.attachments/4810

https://forums.embarcadero.com/thread.jspa?threadID=271608&tstart=0
Brandon Staggs

Posts: 683
Registered: 3/3/01
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 11:00 AM   in response to: Adem Meda in response to: Adem Meda
"Adem Meda" wrote on Sun, 10 Dec 2017 20:05:44 -0800:

BTW, I am aware that this may sound like on odd thing to ask for, but I have to
find a way to prevent our cats from causing havoc with my PC (and/or laptop) by
randomly pressing a key here and moving the mouse there..

Windows-Key+L.

--
Brandon Staggs
StudyLamp Software LLC
http://www.studylamp.com
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 9:30 PM   in response to: Brandon Staggs in response to: Brandon Staggs
Brandon Staggs wrote:

Windows-Key+L.

Afraid not.

That simply locks the OS and brings up a login screen while hiding anything
underneath.
Brandon Staggs

Posts: 683
Registered: 3/3/01
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 4:52 AM   in response to: Adem Meda in response to: Adem Meda
"Adem Meda" wrote on Mon, 11 Dec 2017 21:30:19 -0800:

Brandon Staggs wrote:

Windows-Key+L.

Afraid not.

That simply locks the OS and brings up a login screen while hiding anything
underneath.

Yes, I do see now you have more specific needs.

--
Brandon Staggs
StudyLamp Software LLC
http://www.studylamp.com
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 11:25 AM   in response to: Adem Meda in response to: Adem Meda
Adem Meda wrote:

I am looking for a way to disable/enable input (from keyboard and
mouse) and I need it to work OS-wide.

I am hoping there already exists such a utility and someone who knows
of one will let me have a link to it.

Look at the Win32 API BlockInput() function.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646290.aspx

--
Remy Lebeau (TeamB)
Adem Meda

Posts: 495
Registered: 12/28/98
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2017 9:30 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:


From the linked page:

---- quote
The system will unblock input in the following cases:

The thread that blocked input unexpectedly exits without calling BlockInput
with fBlock set to FALSE. In this case, the system cleans up properly and
re-enables input.

The user presses CTRL+ALT+DEL or the system invokes the Hard System Error
modal message box (for example, when a program faults or a device fails).
---- unquote

It seems there's no other way (other than pressing CTRL+ALT+DEL) for the user
to get out of BlockInput().

I'd like to give user (me, in this case) alternative key combinations.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Disable/enable keyboard and mouse input OS-wide with a key combination
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 10:44 AM   in response to: Adem Meda in response to: Adem Meda
Adem Meda wrote:

It seems there's no other way (other than pressing CTRL+ALT+DEL) for
the user to get out of BlockInput().

Correct, unless the app calls BlockInput() a second time.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02