signal handler fix and some minor changes

main
Shinyzenith 2 years ago
parent 9b8aef428c
commit 35455635c1
No known key found for this signature in database
GPG Key ID: 6DD485917B553B7B

@ -23,8 +23,8 @@ class SWHKD:
self.input_util = INPUT_UTILS()
self.user = getpass.getuser()
async def signalhandler(self,sig,frame):
await self.log_util.log_info('Gracefully quitting.')
def signalhandler(self,sig,frame):
print('\033[1;31mEXIT: Quitting SWHKD.\033[0m')
sys.exit(0)
async def run_swhkd(self):
@ -35,6 +35,9 @@ class SWHKD:
if group.lower() == "input":
await self.log_util.log_warn("User is in input group, proceeding.")
break;
await self.input_util.get_keyboard_devices()
keyboards = await self.input_util.get_keyboard_devices()
for keyboard in keyboards:
await self.input_util.get_keyboard_events(keyboard)
asyncio.run(SWHKD().run_swhkd())

@ -2,7 +2,6 @@
import glob
import libevdev
import asyncio
from . log import LOG_UTILS
class INPUT_UTILS:
@ -10,6 +9,9 @@ class INPUT_UTILS:
self.log_util=LOG_UTILS()
async def check_keyboard(self,device_path) -> bool :
"""
Check if the device is a keyboard.
"""
fd = open(device_path, 'rb')
device = libevdev.Device(fd)
fd.close()
@ -21,6 +23,9 @@ class INPUT_UTILS:
return False
async def get_keyboard_devices(self):
"""
Get all keyboard devices.
"""
devices = glob.glob('/dev/input/event*')
keyboards = []
for device in devices:
@ -28,3 +33,9 @@ class INPUT_UTILS:
if out ==True:
keyboards.append(device)
return keyboards
async def get_keyboard_events(self,device_path:str) -> None:
with open(device_path, 'rb') as fd:
device = libevdev.Device(fd)
for event in device.events():
print(event)

Loading…
Cancel
Save