LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   KDE3 execute command on keyboard shortcut (https://www.linuxquestions.org/questions/linux-general-1/kde3-execute-command-on-keyboard-shortcut-23282/)

hamsterdude 06-12-2002 05:32 PM

KDE3 execute command on keyboard shortcut
 
Do I need to say much more? I use KDE3, is there any way to execute a specific command when a certain set of keys is pressed (eg Alt-F1)?
Any ideas?

DavidPhillips 06-12-2002 05:46 PM

You could edit the shortcut keys scheme in control-center.

You may want to create a script in some cases to actually perform certain functions or run commands, and make a shortcut to the script.

hamsterdude 06-13-2002 01:29 AM

I've looked at that but there doesn't seem to be any way of adding actions, you only seem to be able to edit the keys for stuff like switching desktops

MasterC 06-13-2002 03:12 AM

hamsterdude, (cool name btw) if you could maybe give us an example of what you are trying to do, or an instance in which you would use something like you are talking about, maybe someone could help you further.

If you are looking to perform 3 or 4 functions with the touch of 1 button, I would make a script like DavidPhillips said. For example if you are trying to execute the same program with the same [options] each time, you could make something like this:
Code:

#!/bin/bash
prog name -option

Then you need to make it executable by: 'chmod a+x prog name'
That is a very very simple script, just an example.
Good luck

hamsterdude 06-13-2002 03:24 AM

well, I'm trying to set up hotkeys for Xmms. Failing to find a plugin I realised that you could control it at the command line (eg 'xmms -p' is the command to make Xmms play the current song), so I thought that it would be quite useful if, say, everytime I hit Alt-F2 that the command 'xmms -p' ran and Xmms starting playing. But you don't seem to be able to do this in Kde. Does anyone know any tricks in KDE3 to run a command on a specific combination of keys.

BTW, if you like the name 'Hamsterdude' check out www.hamsterdude.com

MasterC 06-13-2002 03:36 AM

This probably won't help very much, but here's a shot in the dark..

I have a console based MP3player which had some messed up keybindings, like F1 was to switch to a file browsing list, F2 was to load the list and so on. Well I ran a man on the program and found out that I could switch the keybindings. So now I press p to play and so on. I bet there is something similar with XMMS. In fact, I know you can use single keys to control play and such. For example x I think is stop, v is play, and so on.

ANYWAY, to sort of answer your question, the script answer may be a way for you to get what you want. The example would read:
(I am not a programmer, just giving examples from different experiences I have used, so if anyone can clean up, or make my code better, please feel free)
Code:

cat > /usr/local/autoxmms << "EOF"
#!/bin/bash
xmms -p
EOF

Then do a chmod a+x /usr/local/autoxmms

Of course that's a simple script again. You can get very elaborate if you want. Hope this helps.

<edit>
Oh, and I forgot to mention the key part of all that. You could make a symlink in a directory in your PATH, something like:
ln -s /usr/local/autoxmms /usr/bin/PLAY

Or something like that, then when you typed PLAY it would execute your script, which would execute xmms -p and start playing. There is probably an easier way, I just don't know it.
</edit>

hamsterdude 06-13-2002 03:51 AM

A know that when the inittab acript runs, it grabs ctrl-alt-delete for its own evil ends and then monitors that, ready to run 'reboot' or whatever. Is there anyway to do the same, so that when Alt-F1 or whatever is detected, it'll run a script?

hamsterdude 06-13-2002 03:54 AM

here we go, found this in inittab:
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

Does anyone know if you can do the same to trap Ctrl-F1?

MasterC 06-13-2002 05:02 AM

Looks like this mini how to might help you out. There are a few options on assigning keys, I don't know but I am assuming you will be able to set it up with one of the programs mentioned in the how to.

kmc 07-11-2003 08:43 AM

HI
why does nobody understand hamsterdude's simple problem? ;)
i had the same struggle.. searched for it hours and hours... there is nothing in "control center"... (i think it was there in kde1 and/or 2).
i almost started to mess around with inittab, too.
but that probably wont work anyway and it's not necessary.. if you use kmenuedit !!!
you can easily configure global kde hotkeys for executing commands there :)
you just have to add a custom entry for each command you need...
hth!

Bebo 07-21-2003 02:36 PM

Hey kmc!

I'm SO grateful for the tip! I've had no problem to find kmenuedit in SuSE and define my own shortcuts, but in Mandrake I was at a loss since I couldn't remember what the app was called. Great! :D

/Stefan


All times are GMT -5. The time now is 06:53 PM.