kbct icon indicating copy to clipboard operation
kbct copied to clipboard

[Feature Request] Command execution

Open pushqrdx opened this issue 4 years ago • 10 comments

I would like to use this as a replacement for xbindkeys but for this, there has to be a way to execute commands, any chance to have this functionality?

pushqrdx avatar Oct 03 '21 00:10 pushqrdx

Hi @pushqrdx and thanks for your request.

Have you considered using another alternative for command execution other than xbindkeys. For example, I am using i3wm and it gives command execution capability right out of the box. I believe alternatives should exist for gnome,kde,etc. as well.

samvel1024 avatar Oct 04 '21 11:10 samvel1024

@samvel1024 using the window manager hotkeys means that you run into the issue where media keys don't work if a context menu is open, also media keys steal focus from current window for a split second everytime you press them. however if we handle hotkeys at a level lower than X these issues will not happen

pushqrdx avatar Oct 04 '21 15:10 pushqrdx

Hmm, that sounds reasonable.

One possible solution that I use is the following.

Pick a key that you're not going to use (or you don't have on your keyboard). Let's say F13. Now use KBCT to map any key/keycombo to F13. Use another tool to perform arbitrary command execution on F13.

This is obviously not a clean solution, but I use this in my setup and it more or less works.

samvel1024 avatar Oct 07 '21 09:10 samvel1024

@samvel1024 wouldn't that just result in the same issues with X, a context menu grabs the keyboard so if you are handling keyboard events on X level no shortcuts will work there, also if you handle any events on X level it will steal focus from active window

pushqrdx avatar Oct 07 '21 19:10 pushqrdx

Well, as a result KBCT will intercept any of that shortcut that you intended to map to a command, if I understand correctly.

samvel1024 avatar Oct 08 '21 16:10 samvel1024

@samvel1024 yeah this is what i meant by using KBCT as a xbindkeys alternative (which is in your readme already), so i'll be able to create hotkeys that execute commands independent of display server, and side track the issues of handling hotkeys on Xorg level. I can't think of a scenario where i would want KBCT to execute a command AND ALSO pass the keys around, i expect that if for instance i hit VolumeDown and i have that bound in KBCT it will execute amixer set Master 5%- and eat the VolumeDown keyevent

pushqrdx avatar Oct 08 '21 21:10 pushqrdx

Yeah, for that very reason this is also in the readme :smiley:

*However, KBCT is not a tool that can be used to configure macros or arbitrary command execution on a key press. Also note that KBCT requires sudo access.

To be honest, I don't think I see a lot of value in putting efforts towards command execution to kbct. But I will accept a PR if someone wants to work on this feature.

samvel1024 avatar Oct 09 '21 20:10 samvel1024

@pushqrdx, another reason why it may be not the best idea, is that when you run something via a tool such a kbct, it will be run as root (for kbct is required to be run as root). It may have some unintended implications, like, when you try to run something session-related from different user (playerctl as example, or anything related to pulseaudio which has a daemon run in user-unit).

There is another project that attempts to do what you want, though.

yunmikun2 avatar Oct 10 '21 17:10 yunmikun2

@yunmikun2 no i just add my user account to the input group and run as normal user, playerctl works just fine (using hkd) So to be clear i already have a working solution to my problem with hkd, but i thought KBCT would be a bit nicer with added feature of key remapping and allow for hijacking the event instead of passing it through like hkd does

pushqrdx avatar Oct 11 '21 01:10 pushqrdx

If you're on gnome, I recommend the excellent run-or-raise

timcharper avatar Feb 28 '24 03:02 timcharper