Qt global shortcut extension hijacks shortcut - c++

I am using this Qt extension that enables global short cuts (hotkeys) https://github.com/falceeffect/UGlobalHotkey
It works great, however if e.g. you enable the shortcut 'Ctrl+S' (Cmd+S on OSX) - the usual Save shortcut, and run this extension, it will hijack the shortcut and whatever application (Word/Sublime etc) you have in focus never receives the shortcut - EVEN WHEN the Qt app is NOT the focus.
My question(s) is/are:
how can an application take such control of a shortcut like this? Surely thats almost a vulnerability?
Can I 'pass' the shortcut back to the OS or to any other app that is in focus?
What order do shortcuts get registered?
My goal is to just passively recognise that Ctrl+S (Cmd+S on OSX) has been hit, but not hijack it in it's entirety

Alas this can't be done due to limitations of the OS
https://github.com/Skycoder42/QHotkey#known-limitations

Related

Trying to write a c++ console program to change a setting controlled by a windows checkbox

Is it possible to create a keyboard shortcut to switch between the monitor and portion selection of this wacom preferences window, via a c++ console program?
Sorry if this is poorly worded, I've had trouble trying to find the right words to search for ways to do it.
I think it should be possible, although a bit tedious. You should be able to use the Windows API, and try to EnumWindows/EnumDesktopWindows to identify the respective application Window, and its respective controls (which are also Windows).
You should identify the window title, and class ids, for the app window, and the checkbox button controls, then when you enumerate through all the desktop windows, you can identify the ones you are interested in.
Then you can use the SendMessage() API to send messages to the controls (Windows) of interest to manipulate them.
It's a bit tedious, but sounds possible.
An example of use here to get an idea:
http://www.cplusplus.com/forum/windows/25280/

Which is better for MFC application hot key or Accelerator?

We have MFC application which has around 10 image buttons to which we want to provide shortcut keys. Shortcuts will be customizable. I have implemented shortcuts (with no customization right now) with hotkeys using ON_WM_HOTKEY() message.
After searching through Goolge I am little confuse. For example, this question is suggesting hotkey is global for OS, and Accelerator is global for application.
Which one I should use with my application. My shortcut keys will be like Ctrl + Shift + A, and will be customizable.
Secondly, where to keep them. Is it usual to store shortcuts in Windows Registry?
Hotkeys added via RegisterHotKey (or its equivalent in MFC) are definitely system global and you should not use them to trigger functions in your program unless you specifically want the user to be able to trigger them from anywhere.
(e.g. your application might be a screenshot app, and so triggering a function from outside it would make sense)
Normally though you should use accelerators to add keyboard bindings for toolbar buttons etc.
Where you store them is up to you - I would say you should store them wherever you store the rest of your application's configuration data.
The difference between an accelerator key and a hotkey is as the provided link states; an accelerator key press is registered whenever the registered key combination is pressed while the application has focus (normal behaviour). However if you want to register a key combination that works even if the user is using another application while your application is in the background; go for hotkey. Applications that commonly uses this are clipboard managers, screen grabbers and launchers.
Storing configuration in the registry is what I would recommend, however you could also use configuration files stored in the users profile directory.

Prevent a Windows app from stealing the focus

I have created a windows application in C++ and I want to make so whenever I run it, it doesn't steal focus from whichever window is currently focused(or maybe steal the focus and give it back right away). I'm not creating any window so i'm not sure how to change the window style, my program runs in the background.
I couldn't find any answer that worked for C++, is there any way I can do this?
When you start your application by clicking on the EXE or shortcut, Windows Explorer takes focus, not your app. The only way to start your app and not let Windows Explorer take focus is to start your program when Windows starts, via registry key.
Make sure you use the extended style WS_EX_NOACTIVATE when using CreateWindowEx().
See the Microsoft Docs for CreateWindowEx.

NPAPI mac plugin sharing commands with browser

I have a NPAPI plugin running in Safari, Chrome and Firefox. I'm able to handle all key combinations with the event callback, but the problem I'm having is with certain key combinations.
In the plugin, I'm trying to use Command+O to fire the plugin's file open dialog, but the browser is also firing its open file dialog.
Supposedly, returning TRUE for event handling method should report the browser that the plugin handled the event, but I'm having no luck with that.
You neglected to specify which OS you're on; based on the fact that you said "Command+O" instead of "Ctrl-O" I'm assuming you're on Mac. The bad news is that on Mac, all events are passed to the plugin from the browser. If the browser doesn't choose to make it possible to override the handling of an event (and it sounds like this is the case) then there is probably nothing you can do about it, short of possibly using some OS hook to intercept the key event before the browser gets it, which seems risky.
On windows you might have a little more luck, since a windowed plugin should actually get events first before they are passed to the parent window and thus could intercept them. On Mac, though, it's all windowless and you get events when the browser feels like giving them to you.

Stealing focus (for a good reason)

I'm working on a clone of Yakuake and, if you have used it, you'd know that one of it's features is stealing the focus for easiness.
Basically, you hit the "show" hotkey, the app appears and you can write on it.
You could be doing whatever thing with whatever app, (being Yakuake hidden), but as soon as you hit the hotkey, Yakuake appears and steals the focus. I want to do the same with my app.
I know there are some window manager rules that prevent applications from doing this, but Yakuake is doing it, why I'm not able to do it?
Also, this application is meant to be compatible with Windows, Linux and Mac, so no KDE or Gnome or < insert_your_favourite_window_manager_here > hacks; I won't go the detect-WM-and-do-hack way.
PS: I'm doing that app in C++ and Qt4.
EDIT:
Just to make it clear, I'm not asking for any code (but if you actually have some example, I appreaciate it). I'm asking for a way for doing it. What should I do to make the WM assign the focus to my app. Is there any standard way for doing so?
There is the Qt::WindowStaysOnTopHint....
The solution is simpler than I thought. I did an animation with a duration of 0s and at the end of the animation I just did a focus. This did the work.
If you want to do it with a "show" hotkey or shortcut you'll have to create and use a hook on the keybord.
Qt don't provide such things so you'll have to do it by yourself.
you can have a look at this post : QT background process
I don't know for other OS.
When you'll get the right keyboard event from your hook, you can create a window with the "allwas on top hint" and that should by ok.