Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__pycache__/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If you are worried about malicious code, the script is pretty small you can easi
## Dependencies

- Linux (tested under Ubuntu 12.04)
- Python (tested under 2.7.3)
- Python (tested under 3.12.2)
- SoX (in debian based systems install by typing "sudo apt-get install sox");

## Future
Expand Down
6 changes: 3 additions & 3 deletions linux_clicky/detect_keyboards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*-
# Author: Fábio André Damas <skkeeper at gmail dot com>

Expand All @@ -8,7 +8,7 @@
def detect_keyboards():
file_handle = open('/proc/bus/input/devices', 'r')
keyboards = []
regex = regex_compile("event\d{0,3}")
regex = regex_compile("event\\d{0,3}")
for line in file_handle.readlines():
if 'Handlers' in line:
if 'kbd' in line:
Expand All @@ -19,4 +19,4 @@ def detect_keyboards():


if __name__ == '__main__':
print detect_keyboards()
print(detect_keyboards())
6 changes: 3 additions & 3 deletions linux_clicky/play_sound.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*-
# Author: Fábio André Damas <skkeeper at gmail dot com>

Expand All @@ -13,10 +13,10 @@ def __init__(self, filename, volume):
self.volume = volume

def run(self):
cmd = 'play -v ' + self.volume + ' ' + self.filename
cmd = 'XDG_RUNTIME_DIR=/run/user/1000 play -v ' + self.volume + ' ' + self.filename
p = Popen(cmd, shell=True, stderr=PIPE, close_fds=True)
# TODO: Test if limits the number of clicks
p.wait()
if p.returncode != 0:
print '\033[1;31mWe found a error with SoX, did you install it?\033[1;m'
print('\033[1;31mWe found a error with SoX, did you install it?\033[1;m')
p.stderr.read()
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*-
# Author: Fábio André Damas <skkeeper at gmail dot com>

Expand All @@ -14,8 +14,8 @@

# Handle CTRL+C
def signal_handler(signal, frame):
print '\033[1;32mCTRL + C Detected. Exiting ...'
print 'Ignore any errors after this message.\033[1;m'
print('\033[1;32mCTRL + C Detected. Exiting ...')
print('Ignore any errors after this message.\033[1;m')
exit(0)
signal(SIGINT, signal_handler)

Expand Down
22 changes: 11 additions & 11 deletions third_party/evdev.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" evdev.py

Expand Down Expand Up @@ -37,12 +37,12 @@ def demo():
while 1:
event = dev.next_event()
if event is not None:
print repr(event)
print(repr(event))
if event.type == "EV_KEY" and event.value == 1:
if event.code.startswith("KEY"):
print event.scanCode
print(event.scanCode)
elif event.code.startswith("BTN"):
print event.code
print(event.code)

class BaseDevice:
"""Base class representing the state of an input device, with axes and buttons.
Expand Down Expand Up @@ -83,10 +83,10 @@ def __getitem__(self, name):

# evdev ioctl constants. The horrible mess here
# is to silence silly FutureWarnings
EVIOCGNAME_512 = ~int(~0x82004506L & 0xFFFFFFFFL)
EVIOCGID = ~int(~0x80084502L & 0xFFFFFFFFL)
EVIOCGBIT_512 = ~int(~0x81fe4520L & 0xFFFFFFFFL)
EVIOCGABS_512 = ~int(~0x80144540L & 0xFFFFFFFFL)
EVIOCGNAME_512 = ~int(~0x82004506 & 0xFFFFFFFF)
EVIOCGID = ~int(~0x80084502 & 0xFFFFFFFF)
EVIOCGBIT_512 = ~int(~0x81fe4520 & 0xFFFFFFFF)
EVIOCGABS_512 = ~int(~0x80144540 & 0xFFFFFFFF)


class Device(BaseDevice):
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(self, fileNames):
for fileName in fileNames:
self.devices.append(Device(fileName))
for device in self.devices:
print repr(device)
print(repr(device))
self.fds.append(device.fd)

def next_event(self):
Expand All @@ -167,7 +167,7 @@ def close(self):
try:
os.close(fd)
except:
print "Warning - failed to close on or more device file descriptors"
print("Warning - failed to close on or more device file descriptors")
pass


Expand All @@ -179,7 +179,7 @@ class EnumDict:
def __init__(self, numberMap):
self.numberMap = numberMap
self.nameMap = {}
for key, value in numberMap.iteritems():
for key, value in numberMap.items():
self.nameMap[value] = key

def toNumber(self, name):
Expand Down