1

Using the following code to disable my mouse and keyboard for 10 seconds. I'm still able to move my mouse and keyboard while the code is running. also I want to call this function from another script in python but I'm not able to. Any suggestions?

import pythoncom, pyHook, time

start = time.time()
time.perf_counter
elapsed = 0

def windoow(event):
    global elapsed
    if elapsed < 10:
       elapsed = time.time() - start
       time.sleep(1)
       return False

    return True

hm = pyHook.HookManager()
hm.MouseAll = windoow
hm.KeyAll = windoow
hm.HookMouse()
hm.HookKeyboard()
pythoncom.PumpMessages()
An P
  • 21
  • 2
  • To call it from another python file, you need to put all of the code inside a function. When you import a file in python, it 'runs' it, which will create the function definitions. – Woohoojin Jul 19 '19 at 12:59

1 Answers1

0

For me, just two lines of programming solved the problem:

from ctypes import *

ok = windll.user32.BlockInput(True) #enable block

#or 

ok = windll.user32.BlockInput(False) #disable block 
bapap
  • 514
  • 8
  • 25
  • You can put import to start of the code and the other lines, you can put them where you want – bapap Jul 19 '19 at 19:10