How to retrieve key press/release event while GLFW window is in focus, but not process key event on the OS? - c++

With the Win32 API you can hook keyboard events at different stages in this keyboard input model
If I was using the Win32 API, I could a create hook and retrieve the message from the system message queue, do "some stuff", then not send the message to the thread message queue. (I only want to cancel sending the message to the thread message queue if a a specific GLFW window is in focus)
But since I need my program to be cross platform, I'm just using a GLFW key callback to retrieve keyboard input when the GLFW window is in focus.
But if for example the user alt tabs (presses the Windows key on Windows, uses command + space on MacOS, etc.), I need to do "some stuff" with the keys they pressed without the user actually tabbing out of the GLFW window.
The only way the user should be able to drop focus of the GLFW window is if their cursor is out of the window's bounds and click out of it.
If the explanation of my problem is not so good, please let me know.

Related

How could I understand that user pressed X button on cmd window?

I have written a program in C++ and before exit I store some data in files. However, if the user clicks on the close box (X) on top right corner I lose those data. Is there a way to detect if the user clicks on the close box, so that I call some functions before exit?
Use SetConsoleCtrlHandler() to installer a handler that looks for the CTRL_CLOSE_EVENT event:
A signal that the system sends to all processes attached to a console when the user closes the console (either by clicking Close on the console window's window menu, or by clicking the End Task button command from Task Manager).

Need to know windows API to get a callback when my application is activated

I have a wxWidgets windows application, I am launching annother application upon click a certain button on
my appication, This new launched application behaves like to modal window and my application is sent back, But
when user use Alt+Tab or click my appliction icon, My application comes to front, whereas child application
which is already opened should have been shown
I figured how to bring an application to front, Now i would like to know if i can set a callback to parent application
which will be called whenever application is activated (either through Alt+Tab or task bar icon or any other way),
So i can bring my child application to front at this time.Is there a windwos API for this?
WM_ACTIVATE
Sent to both the window being activated and the window being
deactivated. If the windows use the same input queue, the message is
sent synchronously, first to the window procedure of the top-level
window being deactivated, then to the window procedure of the
top-level window being activated. If the windows use different input
queues, the message is sent asynchronously, so the window is activated
immediately.
case WM_ACTIVATE:
{
// test if window is being activated
if(LOWORD(wParam)!=WA_INACTIVE)
{
// application is being activated
}
else
{
// application is being deactivated
}
}
break;
EDIT:
If you want to use a hook to monitor whether the window is switched, you can refer to this link.
Capture switch window event (window focus) (Alt+TAB)

Mouse and Button Event Tracking on win32 GUI program

I have a Win32 GUI program built by Borland C++ Builder 6.
I want to do some user behavior analyses on it by logging users' input.
Such as mouse clicking on which window, buttons clicking messages and components clicking message etc.
First time I tried to insert some C codes in the Click Events of GUI components.
However, there are too many components for me to insert these codes.
Therefore, I want to ask for some methods/libraries to capture mouse and button events depending on message loop or something...

How to close a MessageBox window by its handle with C++

I have a multi-threaded application that may display a MessageBox for a user's interaction. The message box itself is displayed from a worker thread, after a user picks a context menu command from the app's system tray icon, so the user can technically continue using the app while the message box is displayed. This works great until a user issues "Exit" command, at which point I need to find a way to close any open message boxes.
I did my homework and I was able to obtain HWND handle for the main (dialog) window of the message box (using this method.) I checked the HWND to be correct using Spy++, so HWND itself is not the issue. What happens is that when I do PostMessage(hMsgBoxWnd, WM_CLOSE, 0, 0); from another thread to the message box, it simply ignores this message and doesn't close.
Any idea how to close the message-box by its window handle?
MessageBox() simply does not process WM_CLOSE in all sitations:
SendMessage/PostMessage WM_CLOSE to MessageBox window does not always work
You should use PostThreadMessage to post to the threads specific message queue

How to get notified of textbox focus?

Using a Windows 7 touch device Windows shows this little touch-keyboard indicator (tabing this will bring up the touch on screen keyboard) when you tab/focus a textbox or kind of input field (Notepad etc.).
I want to write an application that gets notified when exactly that happens, a textbox (etc.) gets focused (no matter which application).
Are applications informed about focusing in other applications, do I need to hook something?
Is there a way in doing so in c++?
I believe the SetWinEventHook function and specifically the EVENT_OBJECT_FOCUS event is what you are looking for.
From the MSDN description:
An object has received the keyboard focus. The system sends this event for the following user interface elements: list-view control, menu bar, pop-up menu, switch window, tab control, tree view control, and window object. Server applications send this event for their accessible objects.
The hwnd parameter of the WinEventProc callback function identifies the window that receives the keyboard focus.