TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: R.WIESER
from: MARTIN GREGORIE
date: 2018-05-17 21:51:00
subject: Re: Send keystrokes from

On Thu, 17 May 2018 20:03:30 +0200, R.Wieser wrote:

> 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

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

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.