Send keystrokes from a C(++) program to a GUI app ?

Hello all,
I've got a program which receives instructions from an IR remote, and I
would like to pass those instructions on, as keystrokes, to a specific
window*. But although I did find several "its easy to do in Python" and
"this is how you create a keylogger" references, I could not even find a
lead to how to do it in C / C++ **.
*Ultimatily I would check what the active app is, and from it select the
instruction-to-keystroke mapping in my program. (I've also encountered LIRC,
but I've not seen any info in regard to either sending the learned "keys"(?)
to an app or doing dynamic translation).
*
* I found several commandline tools, but that doesn't really help (shelling
from my program to external tools is not really my thing).
tl;dr:
does anyone know how to "sendkeys" in C/C++ to a GUI app.
Regards,
Rudy Wieser
Reply to
R.Wieser
Loading thread data ...
Can't you look in the source for those programs ? That would give you a clue?
--
--
Reply to
Björn Lundin
I've done something similar when I needed to pass single keystrokes into a Java program: Java won't read keystrokes from a Linux terminal application, only a LF-terminated string.
So, I wrote a small C program that tweaked stdin to accept individual keystrokes and passed them, one by one, to the Java app over a socket connection. My application echoes received characters back to the keyreader as a primative form of flow control. The only critical thing with this approach is that the consuming program needs to be up and expecting a connection before the key reader is launched. I used a shell script to deal with startup sequencing:
#!/bin/bash java MyApp & sleep 1 keyreader
though I could have just as easily invoked ProcessBuilder.start() after my application had opened its listener socket - or execve() if it was a C program. I don't see why the same trick wouldn't work for any other data source as well as it does for the keyboard.
--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie
:-) My googeling *should* have turned up such sources, but I did not find anything in that regard. Hence my posting here.
Regards, Rudy Wieser
Reply to
R.Wieser
Martin,
The problem with that is that several of the programs I want to control are already build, and I cannot just change them (think file & webbrowser).
Also, I do not want to control just a single app, I want to be able to control whatever is on the desktop (hence changing the command-to-keystroke table, depending on the focussed app)
... But lets beging with just sending keystrokes.
Regards, Rudy Wieser
Reply to
R.Wieser
Windows or Linux or what?
Reply to
mm0fmf
Look at xdotool at
formatting link

source is at
formatting link

--
--
Reply to
Björn Lundin
On Fri, 18 May 2018 20:33:58 +0200, "R.Wieser" declaimed the following:
Prepare to read the 8 or so volumes of the X-Toolkit/X-window documentation -- since you are talking about injecting X-events upstream of any single application.
Maybe something from:
formatting link

--
	Wulfraed                 Dennis Lee Bieber         AF6VN 
	wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/
Reply to
Dennis Lee Bieber
Does there exist a 'windows' for rapsberry Pi???
--
?Progress is precisely that which rules and regulations did not foresee,? 

  ? Ludwig von Mises
Reply to
The Natural Philosopher
Yes ... but ...
Reply to
Andy Burns

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.