Code:
import pythoncom, pyHook, winsound, os, sys
def hooking(event):
if event.Key == 'F1':
print "Working..."
os.system("lagg.bat")
winsound.Beep(1000,200)
print "ON"
return True
if event.Key == 'F2':
print "Working..."
os.system("lagg1.bat")
winsound.Beep(1000,200)
print "OFF"
return True
if event.Key == 'Escape':
sys.exit()
return True
# return True to pass the event to other handlers
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = hooking
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
Requirements: Python 2.7, pyHook package (pip install pyhook)
You have to put lagg.bat and lagg1.bat in the same directory with your script. (lagg.bat is on, lagg1.bat is off, find it in Syruz's post)
Press F1 and F2 to run the bat files.