Skip to content

Commit

Permalink
Restructure project
Browse files Browse the repository at this point in the history
  • Loading branch information
amamic1803 committed Nov 15, 2022
1 parent c4cc684 commit 4123a07
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Key-Click
A program that makes right arrow key act like left mouse key
A program that makes arrow keys act like mouse buttons


![screenshot](https://user-images.githubusercontent.com/40371578/178462409-c3271caf-f9e2-4fce-9eb8-132f23b5dffb.png)
Expand Down
90 changes: 90 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import datetime
import os
import random
import shutil

import PyInstaller.__main__


def build(name, console, onefile, uac_admin, key, icon, upx, files, folders):
work_path = "build"
while os.path.isdir(work_path):
work_path = f"build_{random.randint(1, 1_000_000_000)}"
work_path = os.path.join(os.path.abspath("."), work_path)

result_path = os.path.abspath(".")

run_list = ['main.py',
'--noconfirm',
'--clean',
'--name', f"{name}_{datetime.datetime.now().strftime('%Y-%m-%d_%H.%M.%S')}",
'--workpath', work_path,
'--specpath', work_path,
'--distpath', result_path]

if console:
run_list.append("--console")
else:
run_list.append("--noconsole")

if onefile:
run_list.append("--onefile")
else:
run_list.append("--onedir")

if uac_admin:
run_list.append("--uac-admin")

if key != "":
run_list.extend(('--key', key))

if icon != "":
icon_path = os.path.join(os.path.abspath("."), icon)
if not os.path.isfile(icon_path):
raise Exception("Invalid icon!")
else:
run_list.extend(('--icon', icon_path))

if upx != "":
if not os.path.isfile(upx):
raise Exception("Invalid UPX!")
else:
upx_path = os.path.join(os.path.abspath("."), os.path.dirname(upx))
run_list.extend(('--upx-dir', upx_path))

for file in files:
if os.path.isfile(os.path.join(os.path.abspath("."), file)):
run_list.extend(('--add-data', f'{os.path.join(os.path.abspath("."), file)};{os.path.dirname(file)}'))
else:
raise Exception("Invalid file!")

for folder in folders:
if os.path.isdir(folder):
for walk in os.walk(folder, followlinks=False):
for file in walk[2]:
if os.path.isfile(os.path.join(walk[0], file)):
run_list.extend(('--add-data', f'{os.path.join(os.path.abspath("."), os.path.join(walk[0], file))};{os.path.dirname(os.path.join(walk[0], file))}'))
else:
raise Exception("Invalid folder!")
else:
raise Exception("Invalid folder!")

PyInstaller.__main__.run(run_list)
shutil.rmtree(path=work_path, ignore_errors=True)

def main():
name = "Key-Click-v2"
console = False
onefile = True
uac_admin = False
key = "DarkLord76865"
icon = "data/key-click-icon.ico"
upx = "data\\upx.exe"
files = [icon]
folders = []

build(name, console, onefile, uac_admin, key, icon, upx, files, folders)


if __name__ == '__main__':
main()
File renamed without changes.
Binary file added data/upx.exe
Binary file not shown.
2 changes: 0 additions & 2 deletions key-click-pyinstaller.txt

This file was deleted.

54 changes: 0 additions & 54 deletions key-click-v1.py

This file was deleted.

98 changes: 98 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import os
import sys
from tkinter import *

import keyboard
import mouse


def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except AttributeError:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)

def s(key):
global stat

if not stat[key]:
for key_iter in range(len(stat)):
if stat[key_iter] and key_iter != key:
match key_iter:
case 0:
mouse.release(button="left")
case 1:
mouse.release(button="middle")
case 2:
mouse.release(button="right")
stat[key_iter] = False

stat[key] = True
match key:
case 0:
mouse.press(button="left")
case 1:
mouse.press(button="middle")
case 2:
mouse.press(button="right")

def r(key):
global stat

match key:
case 0:
mouse.release(button="left")
case 1:
mouse.release(button="middle")
case 2:
mouse.release(button="right")

stat[key] = False

def main():
global stat
stat = [False, False, False] # left - 0 | middle - 1 | right - 0

root = Tk()
root.resizable(False, False)
root.geometry(f"250x125+{root.winfo_screenwidth() // 2 - 125}+{root.winfo_screenheight() // 2 - 62}")
root.title("Key-Click")
root.iconbitmap(resource_path("data/key-click-icon.ico"))
root.config(background="#ffffff")

title = Label(root, background="#ffffff", activebackground="#ffffff", foreground="#000000", activeforeground="#000000", text="Key-Click", font=("Helvetica", 23, "italic", "bold"))
title.place(x=0, y=0, width=250, height=65)

instructions = Label(root, background="#ffffff", activebackground="#ffffff",
foreground="#000000", activeforeground="#000000",
text="left arrow key = left mouse button\n"
"right arrow key = right mouse button\n"
"down arrow key = middle mouse button",
font=("Helvetica", 9, "italic", "bold"))
instructions.place(x=0, y=60, width=250, height=65)

keyboard.on_press_key("Left", lambda event: s(0), suppress=True)
keyboard.on_release_key("Left", lambda event: r(0), suppress=True)
keyboard.on_press_key("Down", lambda event: s(1), suppress=True)
keyboard.on_release_key("Down", lambda event: r(1), suppress=True)
keyboard.on_press_key("Right", lambda event: s(2), suppress=True)
keyboard.on_release_key("Right", lambda event: r(2), suppress=True)

root.mainloop()

for key in range(len(stat)):
if stat[key]:
match key:
case 0:
mouse.release(button="left")
case 1:
mouse.release(button="middle")
case 2:
mouse.release(button="right")


if __name__ == "__main__":
main()
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
altgraph==0.17.3
future==0.18.2
keyboard==0.13.5
mouse==0.7.1
pefile==2022.5.30
pyinstaller==5.6.2
pyinstaller-hooks-contrib==2022.13
pywin32-ctypes==0.2.0
tinyaes==1.0.4

0 comments on commit 4123a07

Please sign in to comment.