This forum has been archived. All content is frozen. Please use KDE Discuss instead.

khotkeys/shortcuts don’t control program in the background

Tags: None
(comma "," separated)
Matthias T.
Registered Member
Posts
3
Karma
0
Dear Readers

I have already posted the following question to the German fora kubuntu.de (http://forum.kubuntu-de.org/index.php?topic=17432) and forum.ubuntuusers.de (http://forum.ubuntuusers.de/topic/mit-k ... ergrundpro). But there was no solution until now. I hope that my question meets the topic of this forum.
On my pc I have installed Kubuntu 12.04.4 LTS with KDE 4.8.5 and Qt 4.5.1, German localisation. Unfortunately khotkeys doesn’t work, like I’d expect it to. The problem seems to me, that khotkeys doesn’t address programs running in a window that doesn’t have the keyboard focus.
There is a pedal connected to the computer (by USB), that sends keycodes the same way, the keyboard does. One of the three push buttons of that pedal device is configured to transmit the keycodes equivalent to [Ctrl] + [Shift] + [F5].
When I’m using 'smplayer' during typing at OOo writer, I can use the pedal to stop/continue playing back an audio file, that contains the dialogue I have to transliterate. But I would prefer to use 'sonic visualiser' (http://www.sonicvisualiser.org). There is an important distinction concerning keyboard control of those programs. 'Smplayer', running in background, can be controlled by command line (xterm, konsole) e. g.: 'smplayer -send-action play_or_pause', whereas the window 'sonic visualiser' is running within, has to have the keyboard focus to get short cuts like [space] toggleling pause/play. Configuring (Dialogue: 'Configure Input Actions settings') the short cut controlling the smplayer was not a big problem. The Trigger (push button of the pedal device) was recognized after creating a new shortcut (System Settings → Shortcuts and Gestures → Custom Shortcuts → New → Global Shortcut → Command/URL). After that I simply entered the command ('smplayer -send-action …') in the text box within the Action tab. This is working well. But I can’t figure out how to set up khotkeys to do the same with 'sonic visualiser'. Instead of using … → Global Shortcut → Command/URL, I have to use ... → Global Shortcut → Send Keyboard Input (re-translation may be not quite correct). Defining the Window by auto detection seems to work well, like described in http://docs.kde.org/stable/en/kde-works ... otkeys.pdf. I tried that with both 'sonic visualiser' an 'kate', the last just for testing purposes. The detected string showing up at the 'Window Title' text box I shortened, to match the program’s name with no respect to the sound or text file it was using. From the drop-down box, I selected 'Contains' instead of 'Is Not Important'. The configuration file (~/.kde/share/config/khotkeysrc) was updated correctly. The new settings are working well, only, when the window of 'sonic visualiser' has the keyboard focus. But there must be some kind of testing, because it does matter if the window characteristics where fitted correctly; if the string I entered there, didn’t match the window title, the trigger caused no effect even when the window has the keyboard focus.
What did I get wrong or miss?

Thanks for reading and standing my broken English

Matthias T.
User avatar
Hans
Administrator
Posts
3304
Karma
24
OS
I don't know if it's possible to send the keyboard input to a specific window (it sound like "Specific window" should do that, but I couldn't get it to work - possibly because I'm not using KWin?). Anyway, I'm pretty sure you can use a workaround like this:

Create a script that runs the following:
1. Activates Sonic Visualiser with e.g. wmctrl, e.g. like this:
Code: Select all
wmctrl -a Sonic Visualiser

Make sure you have wmctrl installed.

2. Send the keyboard input you want with e.g. xte (in some distributions it's part of the xautomation package).
Code: Select all
xte 'keydown Control_L' 'keydown Shift_L' 'key F5' 'keyup Shift_L' 'keyup Control_L'


3. Send "Alt+Tab" using e.g. xte.
Code: Select all
xte 'keydown Alt_L' 'key Tab' 'keyup Alt_L'


Problem solved? Please click on "Accept this answer" below the post with the best answer to mark your topic as solved.

10 things you might want to do in KDE | Open menu with Super key | Mouse shortcuts
Matthias T.
Registered Member
Posts
3
Karma
0
Dear Hans
Thank you for your answer. The tools you used, have been new to me, so I had to play around with them a little. I changed the "action", that is controlling sonic visualiser. It’s only one keystroke, e. g. "space", to stop/continue playback. The shortcut ([Ctrl]+[Shift]+[F5]) in my description is meant to trigger khotkeys to do something. Your script is working well, when I use it with Konsole. But doing so in the context of „custom short cuts“, it only changes the keyboard focus to the window of sonic viewer, not triggering further action. That behavior is similar to that showing up, when I try to type the commands of the script step by step into prompt/command line (not starting a subshell by using a script). After changing the focus, no further action can be triggered. Another problem, I’m afraid of is, that using another shortcut (by another push button of the pedal) to control the rewind function of sonic visualiser, can’t work because of the overhead, caused by repeatedly changing the keyboard focus. That’s why it would be really a pity, if it turned out as impossible to use khotkeys to assign special inputs to specified windows/programs.

Matthias T.
luebking
Karma
0
Even with other window managers or using basic clients like xterm, many events cannot be passed to non-focused clients, or rather the client will ignore them.

You can use "xev -id <window_id_here>" to check whether the key input is received on the X11 level - that does however not mean that the client will react (gtk+ clients will usually not, xterm needs to be configured to accept such input)
Matthias T.
Registered Member
Posts
3
Karma
0
@luebking

Thank you for your answer. You’re quite right. If I configure khotkeys/custom hotkey correct, the "action", e. g. "space" keystroke, reaches the specifyed window an is reported by xev but silently ignored by the program within that window. That’s true for sonic visualiser too. What a pitty! I never would have understood that situation by my own. Thank you again.

Matthias T.
luebking
Karma
0
not sure about the capabilities of khotkeys or that would help you, but you could create a simple bash script
#!/bin/sh
OLD_ACTIVE=`xdotool getactivewindow`
xdotool search --class <class of the visualizer - see xprop> windowactivate
xdotool key ctrl+shift+F5
xdotool windowactivate window=$OLD_ACTIVE

and bind that to a shortcut.
Eventually "windowfocus" instead "windowactivate" will do


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]