commit
88c4f8482f
@ -0,0 +1 @@
|
||||
__pycache__
|
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/python3
|
||||
from utils import SWHKD_UTILS
|
||||
import grp
|
||||
import pwd
|
||||
import getpass
|
||||
import libevdev
|
||||
import sys
|
||||
|
||||
class SWHKD:
|
||||
"""
|
||||
Main Class.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.utils = SWHKD_UTILS()
|
||||
self.user = getpass.getuser()
|
||||
|
||||
def run_swhkd(self):
|
||||
|
||||
groups = [g.gr_name for g in grp.getgrall() if self.user in g.gr_mem]
|
||||
gid = pwd.getpwnam(self.user).pw_gid
|
||||
groups.append(grp.getgrgid(gid).gr_name)
|
||||
for group in groups:
|
||||
if group.lower() == "input":
|
||||
self.utils.log_info("User is in input group, proceeding.")
|
||||
break;
|
||||
|
||||
fd = open('/dev/input/event7','rb')
|
||||
device = libevdev.Device(fd)
|
||||
if not device.has(libevdev.EV_KEY.BTN_LEFT):
|
||||
print('This does not look like a mouse device')
|
||||
sys.exit(0)
|
||||
|
||||
while True:
|
||||
for event in device.events():
|
||||
if not event.matches(libevdev.EV_KEY):
|
||||
continue
|
||||
if event.matches(libevdev.EV_KEY.BTN_LEFT):
|
||||
print('Left button event')
|
||||
elif event.matches(libevdev.EV_KEY.BTN_RIGHT):
|
||||
print('Right button event')
|
||||
|
||||
SWHKD().run_swhkd()
|
@ -0,0 +1,19 @@
|
||||
class SWHKD_UTILS():
|
||||
"""
|
||||
Helper Functions.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.COLOR_RED="\033[1;31m"
|
||||
self.COLOR_GREEN="\033[1;32m"
|
||||
self.COLOR_YELLOW="\033[1;33m"
|
||||
self.COLOR_BLUE="\033[1;34m"
|
||||
self.COLOR_RESET="\033[0m"
|
||||
|
||||
def log_info(self, message:str):
|
||||
print(f"{self.COLOR_GREEN}INFO:{self.COLOR_RESET} {message}")
|
||||
|
||||
def log_error(self, message:str):
|
||||
print(f"{self.COLOR_RED}ERROR:{self.COLOR_RESET} {message}")
|
||||
|
||||
def log_warn(self, message:str):
|
||||
print(f"{self.COLOR_YELLOW}WARN:{self.COLOR_RESET} {message}")
|
Loading…
Reference in new issue