Python acting as a keyboard [duplicate] - python

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Key Presses in Python
I want to know if there is a easy way to make python act as a keyboard. I have a CNC mill that runs off a windows machine using Mach 3.
I want to create a python script that will jog the mill for me. To jog the mill you just press buttons on a keyboard to move normally.
So is there a python library that will act as a keyboard in a different program?

If you must use python, try pywinauto or AutoPy.
I prefer AutoIt or AutoHotKey.

Related

Python backspace (\b) creating checkmark characters [duplicate]

This question already has an answer here:
python IDLE shell appears not to handle some escapes correctly
(1 answer)
Closed 3 years ago.
I'm a Raspberry Pi using Thonny Python's IDE to code, and whenever I try to use a backspace in the form of '\b', it outputs as a check mark:
Like this one
I've already looked at some articles on here and only a few mention a GUI bug within Tkinter, but since I'm not using that I'm not sure what's going on. I've also tested it with a simple print('a\b') command in the IDLE, but it still comes out with the check mark following the a.
For reference, I'm using code from this answer: https://stackoverflow.com/a/39504463/11357553
It's specifically this part that produces the oddity:
sys.stdout.write('\b')
sys.stdout.flush()
I'm simply looking to complete the provided function by deleting the most recent character printed to the spinning cursor. I'm rather new and have been able to solve most of my problems, but this one leaves me stuck.
IDLE does not implement a terminal. It does not process either control characters or escape sequences. Run your program in an actual terminal emulator and not via IDLE.
IDLE uses tkinter to implement its GUI. It uses two TK text areas to form the editor and console parts of its windows.

PyQt4 : Linking buttons to functions [duplicate]

This question already has an answer here:
PyQt : Linking buttons to functions in my program
(1 answer)
Closed 6 years ago.
So I have this GUI that has 2 empty text spots to fill and a "Run" button
I want to make it that the 2 empty text spots go to values in the program and the run button will run the python "Main" program ..
How can i do that ?
You need to have a look at the documentation for PyQt signals and slots. Normally, when you install PyQt you also install some great examples. Walk through the code and it will teach you a lot (search your filesystem for "qtdemo" or standarddialogs.py).
New-style signals and slots
Old-style signals and slots
Here's a snippet from standarddialogs.py:
self.saveFileNameButton = QPushButton("QFileDialog.get&SaveFileName()")
...
self.saveFileNameButton.clicked.connect(self.setSaveFileName)
...
def setSaveFileName(self):

How can I simulate ctrl alt del [duplicate]

This question already has answers here:
Control-Alt-Delete from python or command line
(7 answers)
Closed 7 years ago.
I am trying to generate a python script command line for the shortcut in ctrl alt del or go directly in "change a password", Or any executable file for that shortcut in windows 8.
I already refer to this question but its not working for me.
.NET Simulate Ctrl+Alt+Del Sendkeys
My target is create an app or way directly to change a password in windows 8 or ctrl alt del and then click change a password
Any suggestion/comments, thanks in advance.
As all of the answers on that question state, its very unlikely that you will be able to send this specific key combination.
Crtl+Alt+Del is a privileged key combination in Windows, and I'd guess any rudimentary attempt to simulate it won't be acknowledged by Windows - for a good reason.
Most answers I've seen suggest you'll need to either use the win32com library or ctypes in Python. I won't link to them, but they are searchable using "python simulate crtl alt del".
In either case, you still need to run the app at elevated privileges which still negates the ease of use.
I'd strongly recommend that you don't do this.

Only allowing one instance of a pyqt4 application [duplicate]

This question already has answers here:
PyQt - how to detect and close UI if it's already running?
(3 answers)
Closed 7 years ago.
I have created a pyqt4 app and I want to make it so only one instance (of QApplication) is allowed to run.
The program reads and writes audio files, and if more than 1 instance is running, Windows (linux is fine) throws errors that 2 programs are trying to access the same files. I see a lot of java and C apps that will display a simple dialog if the program is already running, I just want to know how to do this in pyqt4.
A little help?
This kind of programming pattern is called a "singleton" instance or a "singleton application".
Usually it is done with a global mutex or by locking a file early in the life of the program.
And when you program launches, if the file handle is already locked, then you exit.
Qt Solutions has it here: http://doc.qt.digia.com/solutions/4/qtsingleapplication/qtsingleapplication.html
https://qt.gitorious.org/qt-solutions/qt-solutions/source/841982ceec9d30a7ab7324979a0fd5c9c36fd121:qtsingleapplication
It would probably take a bit of work to get those global mutexes/locks to work in pyqt, since pyqt doesn't have the qt-solutions part in it yet as far as I could tell.
Here is an alternative that uses a cross platform python script:
Python: single instance of program
Hope that helps.
Thanks. I Used https://gitorious.org/qsingleapplication/qsingleapplication/source/ca13324b0f5bdfcaf4e379a78108f0bd85fed98a:qSingleApplication.py#L66 And Called QSingleApplication On My MainWindow And Works Fine

Python Print output at same place or position working on IDLE [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to create a spinning command line cursor using python?
python 3 IDLE progressbar/loadingbar
I want to print the output as below:
Percentage: 10%
and only the percentage keeps changing to 20, 30, 40 so on in the same position. Overwriting 10%. I saw many of the posts on stackoverflow. But none of them work right in Python 3.
I tried using \r, \c and even \b but does not work from within print() or sys.stdout()
I am trying this using IDLE and running the program from Python Shell by pressing F5. The environment is Windows.
Please help. Thanks
IDLE does not provide a true TTY/terminal. Sorry.
Test your program by running it from the windows command line:
C:\PythonXX\python.exe path\to\script.py

Categories