From 5f275e4b811bd98cc79565091ba46b793dde4343 Mon Sep 17 00:00:00 2001 From: Justin Lin <61717681+justinlin099@users.noreply.github.com> Date: Thu, 9 May 2024 15:10:13 +0800 Subject: [PATCH] Add custom application/link function --- .gitignore | 1 + CopyandPaste.py | 4 +-- FrameworkKeyCenter.py | 81 ++++++++++++++++++++++++++++++++++++++++--- NSIS.nsi | 2 +- 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a9c6872..7be827e 100644 --- a/.gitignore +++ b/.gitignore @@ -152,3 +152,4 @@ cython_debug/ #.idea/ FrameworkKeyCenterInstaller.exe FrameworkKeyCenterInstaller-v1.0.1.exe +*.exe diff --git a/CopyandPaste.py b/CopyandPaste.py index bfa8689..387daf9 100644 --- a/CopyandPaste.py +++ b/CopyandPaste.py @@ -29,10 +29,10 @@ def check_caps_lock(): if(state == 'True'): label.config(image=copy) - label.config(text=" Copy") + label.config(text=" Copied") else: label.config(image=paste) - label.config(text=" Paste") + label.config(text=" Pasted") # 將焦點返回到當前前景窗口 win32gui.SetForegroundWindow(current_window) diff --git a/FrameworkKeyCenter.py b/FrameworkKeyCenter.py index 128b07f..73186b1 100644 --- a/FrameworkKeyCenter.py +++ b/FrameworkKeyCenter.py @@ -7,18 +7,23 @@ from ctypes import windll import webbrowser import winreg +from tkinter import filedialog SCREEN_ROTATION_LOCATION = "C:\Program Files\FrameworkKeyCenter\components\ScreenRotate\ScreenRotate.exe" COPILOT_LOCATION = "C:\Program Files\FrameworkKeyCenter\components\copilot\copilot.exe" TASK_MANAGER_LOCATION = "C:\Windows\System32\Taskmgr.exe" RICK_ROLL_LOCATION = "C:\Program Files\FrameworkKeyCenter\components\\NGGYU\\NGGYU.exe" CLIPBOARD_CONTROL_LOCATION = "C:\Program Files\FrameworkKeyCenter\components\CopyandPaste\CopyandPaste.exe" -VERSION='Version: 1.0.1' +VERSION='Version: 1.0.2' def donate(): # Open the browser to the donate page webbrowser.open('https://www.buymeacoffee.com/5b32VpsEp5') +def webTest(): + # Open the browser to the custom link + webbrowser.open(customWeblinkEntry.get()) + def save(): # Save the settings apply() @@ -34,6 +39,8 @@ def apply(): key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'Software\\FrameworkKeyCenter', 0, winreg.KEY_WRITE) winreg.SetValueEx(key, 'Switch', 0, winreg.REG_DWORD, 1) winreg.SetValueEx(key, 'Action', 0, winreg.REG_DWORD, dropDown.current()) + winreg.SetValueEx(key, 'CustomLink', 0, winreg.REG_SZ, customLinkEntry.get()) + winreg.SetValueEx(key, 'CustomWeblink', 0, winreg.REG_SZ, customWeblinkEntry.get()) key.Close() #HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\16 #CHECK IF THE KEY EXISTS @@ -51,6 +58,11 @@ def apply(): winreg.SetValueEx(key, 'ShellExecute', 0, winreg.REG_SZ, RICK_ROLL_LOCATION) elif(dropDown.current() == 4): winreg.SetValueEx(key, 'ShellExecute', 0, winreg.REG_SZ, CLIPBOARD_CONTROL_LOCATION) + elif(dropDown.current() == 5): + winreg.SetValueEx(key, 'ShellExecute', 0, winreg.REG_SZ, customLinkEntry.get()) + elif(dropDown.current() == 6): + winreg.SetValueEx(key, 'ShellExecute', 0, winreg.REG_SZ, customWeblinkEntry.get()) + winreg.CloseKey(key) except FileNotFoundError: key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AppKey\\16') @@ -65,6 +77,10 @@ def apply(): winreg.SetValueEx(key, 'ShellExecute', 0, winreg.REG_SZ, RICK_ROLL_LOCATION) elif(dropDown.current() == 4): winreg.SetValueEx(key, 'ShellExecute', 0, winreg.REG_SZ, CLIPBOARD_CONTROL_LOCATION) + elif(dropDown.current() == 5): + winreg.SetValueEx(key, 'ShellExecute', 0, winreg.REG_SZ, customLinkEntry.get()) + elif(dropDown.current() == 6): + winreg.SetValueEx(key, 'ShellExecute', 0, winreg.REG_SZ, customWeblinkEntry.get()) winreg.CloseKey(key) else: print('Switch is off') @@ -97,6 +113,13 @@ def initiate(): key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'Software\\FrameworkKeyCenter', 0, winreg.KEY_READ) switchState = winreg.QueryValueEx(key, 'Switch') action = winreg.QueryValueEx(key, 'Action') + #restoreEntry + customLinkEntry.configure(state='normal') + customLinkEntry.delete(0, 'end') + customLinkEntry.insert(0, winreg.QueryValueEx(key, 'CustomLink')[0]) + customLinkEntry.configure(state='readonly') + customWeblinkEntry.delete(0, 'end') + customWeblinkEntry.insert(0, winreg.QueryValueEx(key, 'CustomWeblink')[0]) winreg.CloseKey(key) if(switchState[0] == 1): switch.state(['selected']) @@ -110,6 +133,8 @@ def initiate(): key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, 'Software\\FrameworkKeyCenter') winreg.SetValueEx(key, 'Switch', 0, winreg.REG_DWORD, 0) winreg.SetValueEx(key, 'Action', 0, winreg.REG_DWORD, 0) + winreg.SetValueEx(key, 'CustomLink', 0, winreg.REG_SZ, '') + winreg.SetValueEx(key, 'CustomWeblink', 0, winreg.REG_SZ, '') winreg.SetValueEx(key, 'ClipboardMode', 0, winreg.REG_DWORD, 0) winreg.CloseKey(key) switch.state(['!selected']) @@ -119,7 +144,31 @@ def initiate(): dropDown.configure(state='readonly') else: dropDown.configure(state='disabled') + + selectDropDown(None) print('Settings initiated') + +def selectDropDown(event): + # Select the dropdown + if dropDown.current() == 5: + #display the custom link frame + customLinkFrame.pack(side='top', fill='x', expand=True, padx=10, pady=10) + customWeblinkFrame.pack_forget() + elif dropDown.current() == 6: + customWeblinkFrame.pack(side='top', fill='x', expand=True, padx=10, pady=10) + customLinkFrame.pack_forget() + else: + customLinkFrame.pack_forget() + customWeblinkFrame.pack_forget() + +def browseFile(): + # open the file dialog to select the application + file_path = filedialog.askopenfilename(parent=root, title='Select an application or files', filetypes=[('Applications', '*.exe'), ('All files', '*.*')]) + if file_path: + customLinkEntry.configure(state='normal') + customLinkEntry.delete(0, 'end') + customLinkEntry.insert(0, file_path) + customLinkEntry.configure(state='readonly') windll.shcore.SetProcessDpiAwareness(1) @@ -128,7 +177,7 @@ def initiate(): root.title('Framework Key Center') -root.geometry('800x500') +root.geometry('800x550') root.resizable(False, False) @@ -171,14 +220,38 @@ def initiate(): switch.pack(side='right') dropDownFrame = ttk.Frame(innerFrame) -dropDownFrame.pack(side='top', fill='both',expand=True, padx=10, pady=10) +dropDownFrame.pack(side='top', fill='x',expand=True, padx=10, pady=10) dropDownLabel = ttk.Label(dropDownFrame, text='Select an action', font=('Segoe UI', 10)) dropDownLabel.pack(side='left', padx=10) -dropDown = ttk.Combobox(dropDownFrame, values=['Screen Rotation', 'Copilot Key', 'TaskManager', 'RickRoll', 'Copy and Paste (Clipboard Control)'], state='readonly') +dropDown = ttk.Combobox(dropDownFrame, values=['Screen Rotation', 'Copilot Key', 'TaskManager', 'RickRoll', 'Copy and Paste (Clipboard Control)', 'Custom Application', 'Custom Link'], state='readonly') dropDown.pack(side='right', fill='x', expand=True, padx=10) dropDown.current(0) +dropDown.bind('<>', selectDropDown) + +customLinkFrame = ttk.Frame(innerFrame) +customLinkFrame.pack(side='top', fill='x', expand=True, padx=10, pady=10) +customLinkFrame.pack_forget() + +# customLinkLabel = ttk.Label(customLinkFrame, text='Custom link/application', font=('Segoe UI', 10)) +# customLinkLabel.pack(side='left', padx=10) + +customLinkEntry = ttk.Entry(customLinkFrame, state='readonly') +customLinkEntry.pack(side='left', fill='x', expand=True, padx=10) + +customLinkBrowseButton = ttk.Button(customLinkFrame, text='Browse', command=browseFile) +customLinkBrowseButton.pack(side='right', padx=10) + +customWeblinkFrame = ttk.Frame(innerFrame) +customWeblinkFrame.pack(side='top', fill='x', expand=True, padx=10, pady=10) +customWeblinkFrame.pack_forget() + +customWeblinkEntry = ttk.Entry(customWeblinkFrame) +customWeblinkEntry.pack(side='left', fill='x', expand=True, padx=10) + +customWeblinkTestButton = ttk.Button(customWeblinkFrame, text='Test', command=webTest) +customWeblinkTestButton.pack(side='right', padx=10) diff --git a/NSIS.nsi b/NSIS.nsi index b3fd0e4..da91756 100644 --- a/NSIS.nsi +++ b/NSIS.nsi @@ -19,7 +19,7 @@ Name "Framework Key Center" -OutFile "FrameworkKeyCenterInstaller-v1.0.1.exe" +OutFile "FrameworkKeyCenterInstaller-v1.0.2.exe" ; Request application privileges for Windows Vista and higher RequestExecutionLevel admin