question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

disable user keyboard, mouse input ?

See original GitHub issue

Hi,

Some methods/functions such as click_input() can be disturbed by user input. Is there a recommended way to prevent this risk? Temporarily disable user mouse/keyboard input?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
vasily-v-ryabovcommented, Feb 13, 2019

Hi @parlar good question. There is Win32 API function BlockInput. It can be used so (at your own risk):

import ctypes
from ctypes import wintypes

BlockInput = ctypes.windll.user32.BlockInput
BlockInput.argtypes = [wintypes.BOOL]
BlockInput.restype = wintypes.BOOL

blocked = BlockInput(True)
if blocked:
    try:
        pass # do something
    finally:
        unblocked = BlockInput(False) # unblock in any case
else:
    raise RuntimeError('Input is already blocked by another thread!')
1reaction
D4v1dW3bbcommented, Sep 29, 2021

Hi @parlar good question. There is Win32 API function BlockInput. It can be used so (at your own risk):

import ctypes
from ctypes import wintypes

BlockInput = ctypes.windll.user32.BlockInput
BlockInput.argtypes = [wintypes.BOOL]
BlockInput.restype = wintypes.BOOL

blocked = BlockInput(True)
if blocked:
    try:
        pass # do something
    finally:
        unblocked = BlockInput(False) # unblock in any case
else:
    raise RuntimeError('Input is already blocked by another thread!')

If you start a script without BlockInput(False), then you unfortunately need to reinstall windows 10 inorder to fix this, or am I wrong? 🤔

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).

see: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-blockinput

Read more comments on GitHub >

github_iconTop Results From Across the Web

8 Ways To Disable or Lock the Keyboard and Mouse Buttons
KeyFreeze is a very simple tool to use. All you have to do is install it and press the large “Lock Keyboard &...
Read more >
How to disable USB mouse and keyboard - Microsoft Q&A
Running regedit in the Run dialog box. Go to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR, and then locate the DWORD ...
Read more >
Python Block Keyboard / Mouse Input - Stack Overflow
This blocks all the keys on the keyboard (the 150 is large enough to ensure all keys are blocked).
Read more >
Is it possible to block local mouse and keyboard input when ...
You can configure the RealVNC viewer to disable sending keyboard and mouse input by going to Options > Inputs and unchecking "Accept Point ......
Read more >
BlockInput - Syntax & Usage - AutoHotkey
Disables or enables the user's ability to interact with the computer via keyboard and mouse. BlockInput, OnOff BlockInput, SendMouse BlockInput, MouseMove ; [v1 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found