-
Notifications
You must be signed in to change notification settings - Fork 1
/
capskeeper_1.py
67 lines (54 loc) · 2.07 KB
/
capskeeper_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 20 10:26:00 2017
@author: panos
"""
#Libraries we need
import pyxhook
import time
import commands
import pyautogui
#initialization
capsstatus = 0
capsstatusnew = 0
capsstatus = commands.getoutput('xset q | grep LED')[65] #THIS IS WHERE WE GET THE INITIAL CAPS LOCK STATUS
#This function is called every time a key is presssed
def kbeventdown( event ):
global capsstatus
#WHEN LEFT ALT IS PRESSED, WE CHECK THE CAPS LOCK STATUS
if event.Key == "Shift_L":
print "Shift Key Pressed!"
capsstatus = commands.getoutput('xset q | grep LED')[65] #THIS IS WHERE WE GET THE CAPS LOCK STATUS
if capsstatus == "2":
print "CAPS LOCK STATUS: OFF"
if capsstatus == "3":
print "CAPS LOCK STATUS: ON"
#This function is called every time a key is released
def kbeventup( event ):
#print key info
#WHEN SHIFT LEFT IS RELEASED, WE CHECKED IF THE CAPS LOCK STATUS HAS CHANGED, TO TAKE THE APPROPRIATE ACTION
if event.Key == "Shift_L":
print "Shift Key Released!"
time.sleep(0.1) # I PUT A SLIGHT DELAY BECAUSE MANY TIMES IT COULDNT CATCH THE CHANGE OF THE STATUS
capsstatusnew = commands.getoutput('xset q | grep LED')[65] #HERE IS WHERE WE GET THE NEW STATUS
if capsstatusnew == capsstatus: #HERE IS WHERE WE COMPARE THE STATUS BEFORE AND AFTER THE LANGUAGE CHANGE
print "CAPS LOCK STATUS DIDN'T CHANGE, I WONT DO ANYTHING!"
else:
print "CAPS LOCK STATUS HAS CHANGED, SENDING CAPSLOCK KEY PRESS..."
pyautogui.press('capslock')
#Create hookmanager
hookman = pyxhook.HookManager()
#Define our callback to fire when a key is pressed down
hookman.KeyDown = kbeventdown
#Define our callback to fire when a key is released
hookman.KeyUp = kbeventup
#Hook the keyboard
hookman.HookKeyboard()
#Start our listener
hookman.start()
#Create a loop to keep the application running
running = True
while running:
time.sleep(0.1)
#Close the listener when we are done
hookman.cancel()