You are not logged in.

#1 2008-09-10 02:06:49

ljshap
Member
From: Ossining, NY
Registered: 2008-01-23
Posts: 160

Programming a "hot key" to start a particular program.

I'm trying to get back to c/c++ after a long absence.  The only programming I've done over the past 8 years was visual basic, a great RAD but the worlds crappiest (pseudo) language.  I'm a long way from writting any real type of programs, but the following question has gotten the best of my curiousity.

  Is there a way in c/c++ to program an extended keyboard key to start a particular program.    This might be the equivalent of the old terminate and stay resident programs in dos where the hotkey would bring up the program, but all other keys would be put back in the keyboard buffer.  The only time I ever  did this was to "intercept" the print screen key and replace that interrupt (int 5 ?) with my code to print the screen to a file.   There were no screen capture programs back then.  What I would like to do is to have the "start" key bring up an old fashion main menu  program which might be usefull with various window managers, at least the ones without icons.  This would leave you 2 key strokes from starting any program in your main menu. 

  I'm not asking how to do it, but whether its possible, and whether anybody has done anything similar.  I know you can remap some keys, but that seems somewhat limited.  This question is premature, but my curiousity got to me, especially since my research didn't come up with anything.

  Thanks


Live Free or Die !

Offline

#2 2008-09-10 02:27:15

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Programming a "hot key" to start a particular program.

It must be possible because most window managers have configurable keybinding modules. I would suggest looking at the source code for various simple window managers and see if you can extract it the code that does what you need. I don't know if window managers are 'special' in that they get to process key events before they go to your new app, but in the worst case you could hack xorg to make your program top dog.

Dusty

Offline

#3 2008-09-10 04:23:51

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Programming a "hot key" to start a particular program.

You can beat what gets done now. I use "xbindkeys" as my hotkey manager, but it doesn't use the full potential of keyboard events (it has no concept of holding down a key). Under X, you get keyboard events from X (through xlib or xcb I guess). I don't know what's responsible for keyboard management under the console, and you probably don't want to touch that (you can define hotkeys in your .bashrc... or .readlinerc?). Anyway, look at the source of xbindkeys for inspiration, and make it better! Good luck.

Offline

#4 2008-09-11 05:29:43

emphire
Member
From: Canada
Registered: 2007-03-21
Posts: 203

Re: Programming a "hot key" to start a particular program.

I've done similar with gizmod (which is written in C++).  Mind you gizmod is way overkill for what it sounds like you have in mind.  It's definately doable.

Offline

#5 2008-09-12 14:56:02

ljshap
Member
From: Ossining, NY
Registered: 2008-01-23
Posts: 160

Re: Programming a "hot key" to start a particular program.

Thanks for the suggestions.  Although I'm a long way from writting the program, the suggestions sound like they might be usefull on their own to make openbox or other window managers easier to use.  I have xfce4-panel installed in openbox, so I know there are solutions to avoid having to access program via the WM menu.  The truth is, I hate GNU-Linux, its too much "fun", kind of like a big virtual erector set.

Thanks Again!


Live Free or Die !

Offline

#6 2008-09-12 18:34:19

emphire
Member
From: Canada
Registered: 2007-03-21
Posts: 203

Re: Programming a "hot key" to start a particular program.

ljshap wrote:

The truth is, I hate GNU-Linux, its too much "fun", kind of like a big virtual erector set.

So true... it's amazing that I ever get anything done. :-)

Offline

#7 2008-09-26 21:27:13

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Programming a "hot key" to start a particular program.

I'm interested in something similar.
What would be the simplest way to listen for a particular key combo, do some action when it is pressed and then pass it on to the window manager ?
Can gizmod do something like this ? Does it have to be programmed ? It shouldn't be overly complicated, should it ?

By key combo I mean a modifier + some other standard key. A number in this case.


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#8 2008-09-27 22:51:23

emphire
Member
From: Canada
Registered: 2007-03-21
Posts: 203

Re: Programming a "hot key" to start a particular program.

It's not too tricky.

- install gizmod
- cp -r /etc/gizmod ~/.gizmod
- cd ~/.gizmod
- edit GizmoDevicesStrings.py if needed
- cd modules.d
- remove any rule sets you don't want/need
- cp 199-Keyboard-Default.py 197-Keyboard-Commands-Default.py

- modify 197-Keyboard-Commands-Default.py to handle your key-combinations
- to get it to handle key combinations, I think you will need to add some code to handle key states
ie: self.ctrl_active=False on startup and control-key up, and True on control-key down

You could add a timer incase the control-key release is not detected.

You could even write a base class to handle the modifier key states:
See bases/GizmoScriptAltTabber for a bit of an example.

I might put together such a base class when I get around to it.

Offline

Board footer

Powered by FluxBB