Capture X11/GTK+ keyboard shortcut events - change desktop/workspace - linux

In Linux (most distros?) there is a Keyboard Shortcuts settings app that lets you set keyboard shortcuts like the key combination that minimizes a window or switches to the next workspace/desktop or moves to the next media track. I want to connect to the event that is fired when the defined shortcut is pressed rather than the key combination as the key combination can change but the event is always the event. Specifically I want to capture the next/previous workspace/desktop events, not the workspace/desktop changing, but the keyboard request to make the change.
However, I cannot figure out where these events are surfaced. Does anyone know where I might connect to these events? I would think GTK+ has some way to surface it, but even if I have to go down to X11/XLib, I'm ok with that.
Ultimately I will code this in python, but for now I'm just looking for a way to capture these events.

Related

How to detect keyboard event while chrome window is created?

I want to show my Chrome extension popup in a window through the click of a keyboard command and hide it once the respective modifier keys are released. It works, but it's not fast enough taking 150ms from triggering to adding the event listeners that detects the modifier-key release.
Problem: the release won't be detected if the user releases the keys too fast.
I suppose there are many ways to improve loading time; or at least I hope.
Therefore I am more interested in key state detection.
Is it possible to detect the state of a modifier-key without an event? I already tried dispatching a keyboard event myself in order to read the modifier key state, but that was a stupid idea...
How to listen to key events during the transition phase when a window is created? Using a content script could work, but since I use global commands, Chrome may not even be focused.
Basically that's how I do it:
using
chrome.windows.create({'url': chrome.extension.getURL("popup.html"),'type': 'popup', ... to show and
window.addEventListener('keyup', function (event) {}); to listen.

Simulating Physical Keypress

So I have a keyboard, and it has a mode where it lights up every key you press.
I was wondering if you could physically simulate a keypress, AHK just sends it directly to the system.
However I need a way to make the keyboard light up, because AHK doesn't do that. The keyboard is not programmable.
Solutions in mostly any language are welcome.
This is not possible, you want to send a simulate keypress to your fysical keyboard. (this is i think a mechanical switch insite the keyboard self, that does do light up if you press a key) and it is only possible if the company did make a keyboard driver that allows you to change the settings (disable - light up) in the Windows Registry. (you did not give me the name of your keyboard but you can then try to searching into the registry for example software/Logitech/settings)

How to prevent an X Window from receiving user input?

I would like to create some windows on a linux desktop for simple layout purposes. I need to avoid user input going to these windows (and I suppose avoiding the windows from gaining focus should suffice for that to happen).
I think that I can do this with the xprop command, by setting the WM_HINTS property, but I haven't found specific documentation on how to do it.
By the way, for an mplayer window, I can do this by using the option -input nodefault-bindings:conf=/dev/null. I simply need a general solution which I can enforce at a low level on any application's window.
Thanks!
A window indicates whether it wants to receive keyboard input by setting the KeyPress and KeyRelease bits in its event mask. If you do not want your window to receive keyboard input, simply do not set those event in CreateWindow()'s event mask. See http://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#requests:ChangeWindowAttributes for more information.
Additionally, you should also set the input focus hints for your window to "NoFocus", as described in section 4.1.7 of ICCCM: http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.7
If you want to fiddle with other applications' windows, you should be able to change their attributes and hints, although this may result in undesirable behavior and/or side effects.

Detect left/right arrow click - Desktop App Windows 8.1

I am facing a problem , i want to change data inside listview on left/right arrow click. I added Key_Up and Key_Down event to page but neither is called when i push buttons (it seems to me that those events only work with input type fields).
Is there a way to achieve this ?
What you are trying to do is more complicated than you probably anticipate. The key events on a single control are simply not sufficient to get you the data you want in a reliable manner. Instead, you need to handle the Accelerator Key Activated event on the Core Dispatcher.
To accomplish this, you can start by looking at my KeyboardHelper service just so you can see how to handle the basics of the keyboard. But the helper doesn't have anything to handle the arrow keys. If you want to handle arrow keys you will need to add some custom logic.
KeyboardHelper class http://xaml.codeplex.com/SourceControl/latest#MVA/201410_UniversalApp/Dispatchr.Client/Dispatchr.Client.Shared/Services/KeyboardService/KeyboardHelper.cs
You should notice that VirtualKey.Left and VirtualKey.Right are explicit in the VirtualKeys enumeration. This means checking for them should be a synch. I think this should be all you need to get this working. Feel free to copy any of the code you can use from that class.
Best of luck!

How do I make a window move to the top of other windows in Gnome when that window already has the focus?

I have an application that sends the focus to other windows but those windows then don't automatically display themselves in the foreground, i.e. on top of all the other windows. Where can I configure the preferences of my window manager so that this is the default behaviour?
In particular I'm using the Ctrl-0 and Ctrl-Shft-0 shortcuts in the MATLAB IDE to move between the command window and the editor window and although the focus seems to be transferred the new window doesn't automatically redraw itself in the foreground.
Not sure of a key binding off hand that does it, but if you alt-click on a window (which allows you to drag a window) it should come to the front.
As codeDr suggests, MATLAB is also kind of bad about repainting its windows. If you draw to a figure while code is executing, the figure does not update unless you execute drawnow or have some similar pause in the execution to allow the GUI to repaint. Since we're talking about MATLAB, the figure command will also cause the indicated figure to come to the front (in fact, it's harder to get it to not come to the front). So you could do figure(gcf) to bring the current figure to the front, or save the figure number with h = figure; and then later do figure(h). Incidentally, if you want to switch current figures without switching focus, set(0, 'CurrentFigure', h) should set h to the current figure.
Your window manager (probably Metacity?) implements focus-stealing prevention so that rogue apps don't pop up windows that would disturb your typing. Matlab needs to raise its window, and give it the input focus with the correct timestamp. If this is being done from a KeyPress event handler, the timestamp for setting the input focus would be the timestamp from the KeyPress event (i.e. the timestamp of the user-generated event that caused a window to be raised/focused).
To politely give the input focus to a window, google for _NET_ACTIVE_WINDOW.
Usually when the window doesn't repaint, it means that the application's main application loop isn't running to refresh the window. Could it be that Matlab is doing some computation or disk activity when you are switching between windows?

Resources