Python: Simulate Keypresses - python

I want to build something like a programming tastature for my soon-arriving windows tablet.
I don't want to use the normal windows 8.1 tastature, because it would take a long time to get
brackets or things like that, so I wan't to build one myself, with buttons, where I need them.
But I've got one problem. I searched around using Google, and I saw, I'm not the only one with that problem - but I didn't find a simple solution either - so:
How do I simulate keypresses to a window?
I'm looking for something like
Sendkey("S")
Another problem was, that the focused windows would be my own tastature at this point, but I want to send the text to another window I clicked before...
If you know the solution, please answer amateur-friendly.
+Thank you for hopefully coming answers.

Related

How to bind keyboard keys to clicks on certain positions on screen Mac

I've been trying to bind my up, down, left and right keys on my keyboard to certain clicks on my screen. I am an absolute noob at Python so I'm really struggling to get it done but it seems like a nice little project to get better at coding.
I was wondering if anybody has some general tips on what libraries, etc. I should be using for this task?
I am by the way on a Mac laptop if that matters.
Thanks in advance!
Use the 'pynput' module to read keypresses and map them to the functions you want to create using an if statement.
Looks like you want to create hotkeys, refer to this video for a detailed explanation: https://www.youtube.com/watch?v=n_dfv5DLCGI

Live Keyboard Input in Python?

I have a laser pointer that I'm using along with my webcam as a drawing tablet, but I'd like to use the extra buttons on it too. They seem to be bound to Page Up, Page Down, Escape, and Period. I can't seem to figure out a way to get the input(which is handled like it's a keyboard) without any windows being selected.
I've tried serial and pyusb, but I've had issues with both of those. I got it to work with Pygame, but as far as I know, you can't receive input without the window it creates being selected. Any ideas?
You could try making a python key-logger. However, it would be much easier to just use Pygame.
CodeSurgeon answered me in a comment.
Looks like there are a lot of youtube tutorials on the subject, surprisingly. This one shows a cross-platform approach using the pynput module, while this one looks to be using a windows-specific approach (pyhook and pythoncom). Can't vouch for either of these as I just found them through some searching, and I am sure there are others as well.
I found that pynput works for me. (Windows 10/Python 3.4)

Click automatically in specific points after recognition of text

I am using MATLAB and SIMULINK and there is something missing there that is driving me crazy, but the question is not MATLAB-related.
At a certain point I have a window like that:
I would like to have the SELECT ALL button. I don't know why, but since a lot of years I am asking this feature to MathWorks but they don't implement it.
Anyway, I decided to do a workaround by myself.
I want to make a small script in Python which detect the text 'Tunable' and after it clicks automatically on ALL the checkboxes.
Is it possible to do it in Python ?
I found a solution to my problem.
If you are interested you can look at it in this video:
VIDEO YOUTUBE
I am happy to share ideas and to know your opinion.

Background python program inspect GUI events

I am thinking of writing a python program that runs in the background and can inspect user's GUI events.
My requirements is very simple:
1) When user right click the mouse, it can show an option; and when this option is chosen, my program should know this event.
2) When user select a file and click some predefined key combination, my program should know this event.
What should I do? Is this a GUI program? I am also thinking that, this program maybe a daemon on the machine and can inspect the user's GUI event, but I am not sure how can I do this.
Thanks.
If you're talking about doing this stuff inside of a wxPython program, then it's all pretty simple. There's a PopupMenu widget for the first one and an AcceratorTable for the second one. If you're wanting to catch mouse and keyboard events outside of a wxPython program, then you have to go very low-level and hook into the OS itself, which means that there really isn't any good way to do it cross-platform. You'll probably want to look at ctypes and similar libraries for that sort of thing.
I've been researching this problem a bit and while I don't have a definite answer, I thought it would be good to share what I found.
First, according to the answers for this question, wxPython cannot track nor control the mouse position outside of the area controlled by the wxPython app. However, as we can see in the answers to this question, under certain circumstances it may be possible to create system-wide hot keys that wxPython can see (although we can also see that this is probably not the optimal solution).
So what will work for the OP? Well, build a cross platform application that does what the OP wants seems almost impossible so I will assume the OP is developing for MS Windows. Following the suggestions in those previous two questions, I looked into the PyWin32 API. It's a little hard to find documentation for it but this question offers some helpful links. A little more digging and I found this tutorial for system-wide hotkeys as well as the win32event.WaitForMultipleObjects and win32event.WaitForSingleObject methods which, if the OP can figure out the proper event, may be what the OP needs to catch menu clicks.
I know it's far from a complete answer but hopefully this can serve as a good jumping-off point for further research.

Python widget/cursor detection?

Beginner python learner here. I have a question that I have tried to Google but I just can't come up with the proper way to ask in just a few words (partly because I don't know the right terminology.)
How do I get python to detect other widgets? For example, if I wanted a script to check and see when I click my mouse if that click put focus on an entry widget on a (for example) website. I've been trying to get it to work in Tkinter and I can't figure out even where to begin.
I've seen this:
focus_displayof(self)
Return the widget which has currently the focus on the
display where this widget is located.
But the return value for that function seems to be some ambiguous long number I can't decipher, plus it only works in its own application.
Any direction would be much appreciated. :)
Do you mean inside your own GUI code, or some other application's/website's?
Sounds like you're looking for a GUI driver, or GUI test/automation driver. There are tons of these, some great, some awful, many abandoned. If you tell us more about what you want that will help narrow down the choices.
Is this for testing, or automation, or are you going to drive the mouse and button yourself and just want something to observe what is going on under the hood in the GUI?
>How do I get Python to detect other widgets?
On a machine, or in a browser? If in a machine, which platform: Linux/Windows (which)/Mac?
If in a browser, which browser (and major version)?
> But the return value for that function seems to be some ambiguous long number I can't decipher
Using longs as resource handles is par for the course, although good GUI drivers also work with string/regex matching on window and button names.
> plus it only works in its own application.
What do you mean, and what are you expecting it to return you? You should be able to look up that GUI object and access its title. Look for a GUI driver that works with window and button names.
Here is one list, read it through and see what sounds useful. I have used AutoIt under Win32, it's great, widely-used and actively-maintained; it can be called from Python (via subprocess).
Here are comparisons by the author of PyWinAuto on his and similar tools. Give a read to his criticisms of its structure from 2010. If none of these is what you want, at least you now have the vocabulary to tell us what would be...

Categories

Resources