X11 stop windows/supper key event from reaching the OS - events

I am making a program that locks my computer by creating a full-screen window and disabling all ways to unfocus the window. For that I need to programmatically disable/enable the Windows key:
Is there a way to catch and stop the windows key event from being passed on to the OS (Ubuntu 21.10) using libX11? From what I understand I am supposed to use XGrabKey but it only blocks Alt-Tab:
XGrabKey(display, ANY_KEY, ANY_MODIFIER, window, False, GRAB_MODE_SYNC,
GRAB_MODE_SYNC)
Also I don't want to disable the whole keyboard.

Related

Windows-10-IOT QT-C++/QML App Fullscreen Gui Frozen when monitor turns back on

ISSUE:
On a touch panel with no keyboard, my QT C++/QML app running on Windows 10 IOT has the fullscreen GUI "frozen", when the monitor turns on (after the user has triggered the touchscreen), after it has timed-out earlier and turned off due to power settings. Mouse cursor still updates.
The QML GUI has "flags: Qt.FramelessWindowHint | Qt.Window"; I do not want to add "Qt.WindowStaysOnTopHint" as it will block the control panel window when it is open from the app. The program is verified to be still running, only the GUI has frozen from the point in time when the screen turned off.
TEMPORARY RESOLUTION:
The only way to "unfreeze" the fullscreen GUI is to connect a keyboard & press the Windows key to show-hide the start menu, or do it programmatically with a manual QML button placed at a known position or on detection of monitor WM_POWERBROADCAST messages.
When the app is not fullscreen, the freezing doesn't seem to be happening.
Is this due to some missing WM_MESSAGES (e.g. WM_PAINT, WM_ACTIVATE, etc) sent by the OS to the app when it is fullscreen, or when the start menu button is pressed?
Can the app-fullscreen-freezing on monitor-turn-back-on be rectified by the app programmatically sending a sequence of WM_MESSAGES to itself, but not the Win button keypress (as the normal user is not supposed to access the OS or see anything related to the OS when the app is running)?
I tried using winAPI SetForegroundWindow() function...?
:-( Fast forward a few days...
With further testing, it seems that using SetForegroundWindow() alone is not consistent/reliable. Sometimes it works, sometimes it doesn't.
The most reliable that works 99.999% of the time is still the VK_LWIN keypress sent by the app. But, as mentioned before, the app user is not supposed to see the start-menu appearing then disappearing. Best if the behavior of the VK_LWIN keypress could be duplicated to the app without seeing the start-menu...

Windows API to disable Filter Keys dialog?

My C++ game allows users to hold down the shift key for a speed boost, but after 8 seconds this causes an annoying dialog to pop up on a fresh Windows 10 machine ("Do you want to turn on Filter Keys?"). Is there a way to disable this programmatically while my game is running?
I suggest you could refer to the Doc:Disabling Shortcut Keys in Games
To avoid these issues, you should disable these keys when running in full-screen mode, and either enable the keys back to their default handlers when running in windowed mode or exit the application.
To turn off these shortcuts:
1,Capture the current accessibility settings before disabling them.
2,Disable the accessibility shortcut when the application goes into full-screen mode if the accessibility feature is off.
3,Restore the accessibility settings when the application goes into windowed mode or exits.
You could try to use SystemParametersInfo to Get and Set System Information.

Running a Windows process while controlling the mouse and keyboard

I have a Windows program which has a GUI that runs on a PC.
In order to automate some of the GUI actions, I want to be able to move the mouse and type using the keyboard, but without interfering with the user's activity.
I know that I could simulate input events using SendMessage and PostMessage, but that requires the window to be in focus, and I want to eliminate this requirement.
My question is - is it possible to implement sort of a 'wrapper' that internally runs the original program, while patching its mouse and keyboard, providing it with a 'virtual' version of a mouse of keyboard?
I think of that as taking only the mouse and keyboard capabilities of a VM. Is something of that kind exists?
Thanks!

Run a program on: hard "Power" button press

I want to run a program (exe file) when the Power button of my laptop is pressed. (Not when system is shutting down)
I tried getting its keycode using c# and js, but none of them capture this keypress as they only capture keyboard buttons. Look at the drop-down menu I have opened:
My problem would be solved if they add "Run a specific program..." in this drop-down:
But of course they won't add this option!
So, how do I get it done? Maybe using Task Scheduler?
There's no keycode for the power button. The driver is sitting between your OS and your hardware. When you push the "G" button on your keyboard, the driver translates that to an OS system call representing the "G" key which your program can listen for and intercept. But there's no OS system call for a representing the "power" button. Instead, your driver is translating that to OS system calls to initiate a shutdown, turn off the monitor, etc.
Your laptop driver allows you to configure which system call you want to initiate when the power button is pressed, but that driver is going to be unique to the brand and model of your laptop, and if they don't offer support for capturing that keypress through their driver, then you probably don't have any easy way to intercept it.

How do I make a fullscreen window minimize when I hit the windows key?

I've always noticed that in windows games, when you hit the windows key, the screen changes its resolution back to normal, the game window minimizes, and the start menu pops up. When I do it, the start menu just pops up over my window. How do I do it right?
Have you tried using a Low-Level Keyboard Hook to catch the initial Windows key KeyDown event and then process a WM_SIZE message to minimize the window before continuing to process the Windows key keypress?

Resources