LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-31-2013, 12:14 AM   #1
Automatic
Member
 
Registered: Mar 2013
Posts: 42

Rep: Reputation: Disabled
If I push a button on one input device, have one script run, else, run the other?


Basically I have a HTPC that only has a USB IR remote plugged into it, however, since the hardware can run steam (With it's new "Big picture" mode & coming to linux) I'd like to plug in my 360 controller and use that.

However, main issue is switching between plex (Movie software) and steam big picture (Game software). Is there a way to say:-

Code:
if I'm using my 360 remote and steam isn't open, kill plex and launch steam
if I'm using my remote and plex isn't open, kill steam and launch plex
if both plex and steam are open, kill steam
if neither plex or steam are open, launch plex
 
Old 03-31-2013, 01:08 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
What you're asking is very doable. Use xev to display key codes when you press buttons and then xmodmap to modify your key mapping.

The script to launch based on your request could easily be written in bash. I'd recommend writing a kill_wait() function which kills a process with SIGTERM and waits for that process to actually exit before continuing the script. It could look something like this....
Code:
function kill_wait() {
    kill -15 $1
    while [ ! -z "$(ps aux | awk '$2 == "'$1'" {print $0}')" ];do sleep 1;done
}
#Usage:
#  kill_wait PID
#Where PID is an integer of the process id.
Note: my above kill_wait function is completely untested.

You'll have to use the ps command with other tools like grep or awk or what have you to determine if a program is running. Steam and plex should shut down gracefully with SIGTERM and the wait ensures that the program gets a chance to completely shut down before it starts another.

edit: here's a decent resource on how to map keys to a script. I'd like you to note that if you're modifying the key configuration of your controller I'm not sure how it will behave with the default behavior of Steam and having input being captured. Also, I'd recommend breaking your logic down into a couple of scripts to be launched using keys on the remotes. However, I don't think a single script would be too hard either.

Source for coming up with answer. I've used xev before customizing keyboard shortcuts for my openbox interface. It's quite handy.

SAM

Last edited by sag47; 03-31-2013 at 01:26 AM.
 
Old 04-14-2013, 02:17 AM   #3
Automatic
Member
 
Registered: Mar 2013
Posts: 42

Original Poster
Rep: Reputation: Disabled
After looking for awhile:-
http://i.imgur.com/LEXHuWM.png

And trying way to many commands that have probably screwed up my system, I'm still unable to map my right mouse button to the "M" key. Any help? I'm sure it's easy and I'm just stupid, but, I've found no way yet. However, I will note that I've been able to map keyboard keys to keyboard keys (here), keyboard keys to mouse keys (Same as before, here) and mouse keys to mouse keys (xinput)... just not mouse keys to keyboard keys.

Last edited by Automatic; 04-14-2013 at 02:20 AM.
 
  


Reply



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
help with auto run script when usb storage device is plugged in twon Linux - General 3 06-30-2009 03:48 PM
Run script when determined device is mounted pslacerda Linux - Newbie 2 01-21-2009 04:15 PM
Auto run a script when connecting a USB device strangeslack Slackware 1 11-16-2007 12:40 PM
How to make the right mouse button run a script (event trigger) xmrkite Linux - Hardware 5 10-17-2006 01:29 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:35 AM.

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
Open Source Consulting | Domain Registration