LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-27-2011, 12:19 PM   #1
acousmetre
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Rep: Reputation: Disabled
shell script running in background needs to receive keystrokes.


Hello list,

I am writing a simple bash script to launch an image viewing application in full screen mode - and keep this open window updated interactively via keystrokes. Once this viewing application is launched, the shell script loses focus and canīt receive keystroke data. Can the shell script somehow respond to keystrokes even when another process has focus?

Cheers,

Iain
 
Old 06-27-2011, 01:22 PM   #2
aysheaia
LQ Newbie
 
Registered: Jun 2011
Distribution: Ubuntu
Posts: 26

Rep: Reputation: Disabled
One idea :
Communication between two independant processes can be done with the help of IPC. In the case of shell script, the simplest is to use FIFOs (names pipe).
So, whenever the viewing application receives keystroke data, it can send the relevant information to the shell script via the FIFO.

At http://www.linuxjournal.com/content/...pes-fifos-bash, you have an example of a FIFO used for establishing a communication between two shell scripts :
the first one which creates the FIFO and reads whatever is written within (for you : your shell script) ; the second one which writes whatever is useful in the FIFO (for you : your viewing application).
 
Old 06-27-2011, 02:15 PM   #3
acousmetre
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks very much. I understand the way the scripts are operating in the link you sent - but with my problem, how can I channel the incoming keystrokes from the open viewing application to the pipe?

At the moment the viewer is launched from the main script with:

/usr/bin/geeqie -f -o fotos/preto.jpg&

sorry if iīm missing something obvious.

cheers,

Iain
 
Old 06-27-2011, 02:40 PM   #4
aysheaia
LQ Newbie
 
Registered: Jun 2011
Distribution: Ubuntu
Posts: 26

Rep: Reputation: Disabled
Well, if the viewing application is not an application you have written (that is that you can customize), what I suggested cannot work...

The only solution I can see is then to use (or write/adapt) a keylogger but :
- a standard keylogger needs to be launched by root
- it will catch too many things
beside potential ethical questions.
 
Old 06-27-2011, 05:32 PM   #5
acousmetre
LQ Newbie
 
Registered: Jun 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks aysheaia. I found a way around the problem using a second monitor which i just borrowed - and actually my application involves a laptop coupled with a projector (itīs for a theatre show with actors projecting photos of themselves taken from the laptop) - so with the two screens thereīs no problem with a lack of focus on the image-display screen. Iīd be interested to know though if there is a way to launch an app and have itīs keyboard input routed to another - but yes, i can see there might be some privacy issues if misused.
cheers, iain
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem running a program/script in the background from a script newbie01.linux Programming 5 03-28-2011 08:28 AM
How to stop a process running in background (on a shell script) Azk00 Linux - Newbie 3 02-01-2008 05:24 AM
How to run a shell script in a background? anandv_1234 Linux - Newbie 3 12-23-2007 04:03 AM
how do i get a shell script to run in the background? tjyorkshire Programming 4 07-06-2007 03:28 AM
running in background hangs on shell logout pfaendtner Linux - Newbie 5 03-25-2005 11:34 AM


All times are GMT -5. The time now is 01:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration