How to send raw input as if from keyboard or mouse? - python

I am trying to write a macro using python.
I want it to do a repeated task within another program.
I believe the program that I am attempting write this macro only
accepts raw input from keyboard and mouse input stream.
Using python libraries such as pynput.mouse, mouse, pyautogui, so on
seem to be sending a different type of keyboard/mouse input that the program
will not recognize. (Those libraries do work to control and move the mouse
around my computer screen but do not work in the program)
It was suggested that the program accepts only input directly from the keyboard
and mouse (ports?).
How can I write code that sends data as "raw" to the program, or reroute it through the correct (port?) input stream so that the program reads it as "raw"
I hope I was able to explain this clearly.

Please see the following post: ctypes mouse_events
It explains how to do this with raw win32 messages which will do the trick.

Related

How can I take inputs from a midi keyboard on python?

I have a project about midi keyboard.
But I don't know how can I get inputs from it?
İs there a library or else?
(For example, getting information from user about pressing the DO note.)

Python catch keyboard input in the background and process it

I'm currently working on a python program that is supposed to catch all keyboard input and then depending on the input given emulate a keyboard input
For example, I type the letter a into for example windows notepad
my python program catches this returns an emulated keyboard input for example b
what would be the best way to catch the keyboard input?
I looked into the possibility of using a modified keylogger however I ran into an issue how do I stop for example character a from being typed ?

Python keyboard events - Hide user input and send keys to buffer

Hi,
I am working on a project and I am monitoring the keyboard with the keyboard module.
My application works in real-time (on-the-fly) and read strings entered from user (with the keyboard module as mentioned)
What I want to do is hide user input when some specific conditions are True.
I have searched all the web and didn't manage to find something that does what I want.
To give it a more detailed explanation lets say that the user enters some text and this text string-by-string is being checked for some condition from my program.
If everything is OK, then nothing happens but if not, then I want the next user input not to be shown in the position he is writing.
I found solutions that do exactly this in the terminal like the msvcrt module (How to temporarily disable keyboard input using Python ) or do the above functionality with the input() function.
Is there something that prevent the text ,entered from the keyboard, from showing to the screen, but send it to a buffer for editing first.
Thanks in advance.
! I am on windows

Keyboard output to multiple programs simultaneously?

My issue currently is that of emulating keystroke input to an arbitrary program (such as a running game).
Currently I am using win32 libraries on Windows to find windows (win32gui.FindWindow) and grab focus (via win32gui.SetForegroundWindow), then send keyboard input (win32api.keybd_event).
This works if I am only sending input to a single program, but I wish to parallelize, playing multiple games simultaneously. This does not work with my current method as both applications demand "focus" for the keys to go to the right application, thus interfering with each other.
Ideally I would like something that sends input to a given window, that does not require focus , and is independent of input given to other windows or the currently focused window.
My understanding is, only the foreground window get the focus and can handle keyboard input to play. Not sure in make sense to send input to background window or not....

Python redirect stdin

I'm trying to set up a barcode scanner object that will capture anything input from the scanner itself. The barcode scanner is recognized as a standard input (stdin) and therefore whenever I scan a barcode, I get standard input text. There will also be a keyboard attached to the system, which is another standard input. In order to differentiate between a barcode scan input and keyboard input, I will be using a prefix for any barcode information. In other words, if my barcodes will be 16 characters in length total, the first 4 would a predetermined character string/key to indicate that the following 12 characters are barcode inputs. This is pretty standard from what I've read.
Now most examples I've seen will recognize the barcode input by capturing the character input event in a GUI application. This event callback method then builds a buffer to check for the 4 character prefix and redirects barcode input as necessary. The event callback method also will skip any character input events that are not barcode related and allow them to interact with the GUI as a standard input normally would (type into a text box or what have you).
I want to do this same thing except without using a GUI application. I want my barcode scanner object to be independent of the GUI application. Ideally I would have a callback method, within the barcode scanner object, that stdin would call every time a character is input. From there I would grab any barcode input by checking for the 4 character prefix and would pass along any characters not apart of the barcode input. So in other words, I'd like stdin to pipe through my barcode scanner callback method, and then have my barcode scanner call back method be able to pipe non barcode characters back out as a standard input as though nothing had happened (still standard input that would go to a text box or something).
Is this possible without a while loop constantly monitoring stdin? Even if I had a while loop monitoring stdin, how would I pump characters back out as stdin if they weren't barcode input? I looked into using pyusb to take over the barcode scanner's USB interface, but this requires root privileges to interact with the hardware (not an option for my project). Any help would be greatly appreciated. I have not been able to find an example of this yet.
Edit: This project will be run in CentOS or some flavor of Linux.
The normal way of intercepting standard input in Unix is pipes and multiple processes. If you have a multi-process application, then one process can receive the "raw" standard input, capture barcode input, and pass on the rest to its standard output. That output would then be the standard input of your UI process which would only receive non-barcode data. To set this up initially, have a single launch process that sets up the pipes, starts the other two processes, and exits.
If you're new to these concepts, you have a long and interesting learning process ahead of you :-)
All this assumes that you really are receiving "keyboard" data through standard input, and not through X11 events as you seem to imply. If you are developing within X11 (or GTK, etc.) then what I have described will almost certainly not work.

Categories

Resources