• 0

C++ Send Keypress/Code to a child process


Question

Background/Description:

I have recently gotten a raspberry pi, and have decide to not use a Desktop Environment. I have QT, and other development packages installed, however without QT-Embedded, I can't use the virtual windowing tools that QT Comes with. I wanted to create a media center style PC without the fancy additions of XBMC and other media centers. As I don't have a DE/Window system I can't run anything with a gui. I wanted to make a system that would allow me to run/play movies on the pi from any of my devices (Phone, Tablet, Desktop). So I have decided to make a GUI/Server on my computer that would control the PI via TCP. I would use PHP for a web system that would create trigger files that a FileSystemWatcher would pick up for the mobile devices, and will use a direct C# gui on the desktop.

I can do this with no problem as it is done with a standard TCP Connection. I will send commands such as: ~MSFS; to Mount the Shared file system (if not done), ~PV;FileName to Play the Video using omxplayer. All of this is pretty easy and as I will drive everything from the desktop it isn't a lot of pi side stuff to do. Now the problem is.. by forking the process I lose the direct input into the program, and as I will be running it externally instead of on the device I don't get the direct CLI input. As it is all command line, I pause videos by pressing "p". I am sure there are other commands I just haven't looked into them.

The Need:

As I will be controlling it from the PC Server I want to have the ability to send commands such as ~PAUSE; or equivelant, from the desktop to the pi, and have it send the 'p' key to the omxplayer. I have read about using pipes to communicate between parent a child processes, however as I am not taking input via command line for this it would be done all internally during the TCP Packet processing, I don't know how to get that stream. In C# it would just be a memorystream or stock stream that I could just save off and call good. I am not sure if I can do that with the pipe. Now, pausing is just an example, however having the ability to pause a video is a good thing, and would really be a requirement in making it useful.

TLDR;

I am making a client/server program for my Raspberry PI, that will run a child process. I need to send a specific key to the child process when a specific packet is sent. ie) Server Sends ~PAUSE, Client Processes and sends the "p" key to the child process, which then should pause the video (as that's how it works when I run the program directly, hitting p will pause it). How do I do it?

2 answers to this question

Recommended Posts

  • 0

I have no experience with this specifically, but my first thought is that it sounds like a task for signals. If you don't have direct control of the other program (e.g. you didn't write it), then that might not be feasible. The GNOME Onscreen Keyboard sends virtual kepresses... somehow, so I'm sure you could download the source code and take a peak at their implementation. I would definitely be interested in your solution when you get this working though.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • It's the only reason I finally have an iPhone (for work) and enjoy using it so much that I'm tempted to move from android next time I need to replace my own device
    • So is Russia, China, Iran, North Korea, just to mention a few. What's your point? Everyone is a threat from their enemies' perspective. I'd say that Israel is only a threat to their immediate enemies like Hamas, Hezbollah and the Iranian regime, not to anyone else.
    • The government is not the good guy either. You propose 99% of people require that the government overreach and govern their freedom of information and privacy, while ignoring the government is made up 100% of people, of which 99% are (as you described) brain dead. You can't have both. The reality is Signal is absolutely right and the government is doing what it has always done. Ignoring that we are their boss and grabbing all the power they possibly can to make sure we aren't. Your (societies) ###### parenting is not reason enough as to why I can't have a safe platform for my data/information. Thinking the government is helping is precisely what they are targeting psychologically to take suckers like you for a ride. "Think of the children" was, has, is, and will always be a mechanism of control. In the rare occasion it's actually essential the mass consensus has always been there and it doesn't become a debate.
    • Google Chrome 149.0.7827.103 (offline installer) by Razvan Serea The web browser is arguably the most important piece of software on your computer. You spend much of your time online inside a browser: when you search, chat, email, shop, bank, read the news, and watch videos online, you often do all this using a browser. Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier. Use one box for everything--type in the address bar and get suggestions for both search and Web pages. Thumbnails of your top sites let you access your favorite pages instantly with lightning speed from any new tab. Desktop shortcuts allow you to launch your favorite Web apps straight from your desktop. Chrome has many useful features built in, including automatic full-page translation and access to thousands of apps, extensions, and themes from the Chrome Web Store. Google Chrome is one of the best solutions for Internet browsing giving you high level of security, speed and great features. Important to know! The offline installer links do not include the automatic update feature. Download web installer: Google Chrome Web 32-bit | Google Chrome 64-bit | Freeware Download: Google Chrome Offline Installer 64-bit | Direct Link | 131.0 MB Download: Google Chrome Offline Installer 32-bit | Direct Link | 119.0 MB Download page: Google Chrome Portable Download: Chrome ARM64 | Direct Link View: Chrome Website | Release Notes Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Very Popular
      Captain_Eric earned a badge
      Very Popular
    • One Month Later
      amusc earned a badge
      One Month Later
    • One Month Later
      DJC50PLUS earned a badge
      One Month Later
    • Week One Done
      DJC50PLUS earned a badge
      Week One Done
    • Proficient
      Eric Biran went up a rank
      Proficient
  • Popular Contributors

    1. 1
      +primortal
      509
    2. 2
      PsYcHoKiLLa
      222
    3. 3
      ATLien_0
      92
    4. 4
      +Edouard
      86
    5. 5
      Steven P.
      81
  • Tell a friend

    Love Neowin? Tell a friend!