You need to catch all input events on a system-wide level. This is done using Windows Hooks. Start here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx[
^].
You can only install the global (system-global hook) in a DLL using
SetWindowsHookEx
. The code of the hook should communicate with the host application. You should understand that the hook handler code does not have to belong to your thread or process, so you should use some inter-process communication to access event data.
As far as I understand your problem, I would use global named event objects. You only need to wait for some first input event. You can create some thread in the host application and put it to wait state by the call to
WaitForSignleObject
on the handle of the event object. The OS will switch the calling thread off and won't schedule it back to execution until it is waken up by the signaled event. Signal the same event in your hooked event handler. The thread will wake up and do some action which you should call in the next line.
Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396%28v=vs.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682400%28v=vs.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686211%28v=vs.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms685081%28v=vs.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687032%28v=vs.85%29.aspx[
^].
See the article referenced in the last link (for example) for other synchronization primitives.
Read the event object and overview:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682655%28v=vs.85%29.aspx[
^].
—SA