Screen Capture Update
My wife, the user of the Screen Capture application as described in
http://www.sorescu.eu/article/120220221500/Free-Screen-Capture-application explained me that she needs to run it also while in
Full Screen mode.
For this I had to hook to the Windows Hot Key events, after I registered with the desired shortcut.
The chosen shortcut is
<CTRL>+<ALT>+<PRINT_SCREEN>, and the code update is as in file below.
Main call as following:
Thread t=new Thread(new ThreadStart(ProcessHotKey));
t.IsBackground=true;
t.Start();
Worthy mentioning are the following:
- I used
GetMessage(ref msg,IntPtr.Zero,0,0)
for avoiding message queues to any form, but to the current thread; - It was required
int hashCode=("hash-"+modifiers+"-"+key).GetHashCode();
to ensure that the Hot Key is unique in Windows; - The Hot Key handler had to be ran in a separate thread, using
new Thread(new ThreadStart(ProcessHotKey))
My sources of inspiration were:
RegisterHotKey.cs
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd,int id,uint fsModifiers,int vk);
public const int WM_HOTKEY=0x0312;
public const int MOD_ALT=0x0001;
public const int MOD_CONTROL=0x0002;
public const int MOD_NOREPEAT=0x4000;
public const int MOD_SHIFT=0x0004;
public const int MOD_WIN=0x0008;
[DllImport("user32")]
public static extern
bool GetMessage(ref Message lpMsg,IntPtr handle,uint mMsgFilterInMain,uint mMsgFilterMax);
public static void ProcessHotKey() {
uint modifiers=MOD_CONTROL|MOD_ALT;
int key=(int)Keys.PrintScreen;
int hashCode=("hash-"+modifiers+"-"+key).GetHashCode();
if(!RegisterHotKey(IntPtr.Zero,hashCode,modifiers,key))
throw new Exception("Key not registered");
System.Windows.Forms.Message msg=new System.Windows.Forms.Message();
while(GetMessage(ref msg,IntPtr.Zero,0,0))
if(msg.Msg==WM_HOTKEY)
CaptureImage();
}
#endregion