Created
June 21, 2021 02:39
-
-
Save smartass08/b75c5d815523647643d2222adf8f49ab to your computer and use it in GitHub Desktop.
A digital counter in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from pynput.keyboard import Key, Listener | |
count = 0 | |
class bcolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKCYAN = '\033[96m' | |
F_Magenta = "\x1b[35m" | |
F_LightMagenta = "\x1b[95m" | |
F_LightBlue = "\x1b[94m" | |
F_Yellow = "\x1b[33m" | |
OKGREEN = '\033[92m' | |
F_Red = "\x1b[31m" | |
def show(key): | |
print("\033[H\033[J") | |
if key == Key.space or key == Key.enter: | |
global count | |
count += 1 | |
print(bcolors.OKBLUE, "Current count = {}{}".format(bcolors.OKGREEN, count)) | |
if key == Key.backspace: | |
print("Exiting Program\n\n\nFinal count : {}".format(count)) | |
return False | |
def main(): | |
if len(sys.argv) > 1: | |
if str(sys.argv[1]) == "-h": | |
print(bcolors.OKBLUE," A simple digital counter written by smartass08 for college's project\n\n", | |
bcolors.F_Red,"Press either Space or Enter to increase the count\n", | |
bcolors.F_Red,"Press Backpace to stop and display the final count") | |
quit() | |
print(bcolors.F_Yellow, "Minimalistic Digital Counter written by{} smartass08".format(bcolors.F_LightMagenta)) | |
print(bcolors.F_Red, "\n Pass {}-h{} as arg to print help\n".format(bcolors.OKGREEN, bcolors.F_Red)) | |
with Listener(on_press=show) as listener: | |
listener.join() | |
quit() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment