2
votes

How can I input something like CTRL+'something' / SHIFT+'something' / ALT+ 'something' to my python script.

BACKGROUND: I'm trying to build a python based application where my script will keep running in the background no matter what application or program I'm actively using, and when I press a keyboard shortcut (that I want to know how to assign), the script will act up (do something that I've programmed it to do).

I'm a beginner and have no Idea how windows or other desktop applications take keyboard shortcuts as input and perform tasks.

I do know that keystrokes like CTRL/SHIFT/ALT cannot be given as console inputs to a python script. Then how can I program such shortcuts into my application?

All my web searches have led to questions like "How to 'simulate' keystrokes in python" but none have given me a basic explanation of how shortcuts actually work. Is there anything to this other than python (some windows framework maybe)? Please help!

1

1 Answers

2
votes

Keyboard Shortcuts Works like this: The Computer Wait for, if you press a key combination on your keyboard, and if the right combination is pressed it will execute a part of Scripting Code (Computer Macro Movements) - The scripts can be written in languages like: Autohotkey,Autoit or Python

Note: In many Windows Applications you can use Keyboard Shortcuts Combinations to do a Function Command or do a Computer Movement.

If you want to make Keyboard Shortcuts Macros in Python Languages, You Can use AutoPythonLauncher Software.

With this You can Make on your Windows System, a set of Executable Pictures that can run Python Scripts. You can Click With your Touch or Mouse Device on these Toolbar images and it will execute (native) the python Code. (without Focus The Windows this means, that you can [Send any text] or [send any Keyboard Shortcuts] to [Any sort of Applications])

Example:

import pyautogui
import Tkinter as tk     
from pyreg import *

#copy the selected text to the clipboard 
pyautogui.hotkey('ctrl', 'c') memory.


a = tk.Tk()

#Read the clipboard memory and put it in variable b
b = a.clipboard_get() 

#Put the selected text Value in the Windows Registry.
writeregstring('Software\AutoPythonLauncher 1.0\clipboard 1\KeyHintText','1',b)