My application is able to detect if the shift key is pressed but only for the first modified key. The second modified key(even when shift is held down) is detected as unmodified even while the key is still held.
I want to be able to properly detect if the key is modified by shift after the first modified key(e.g. for second, third and so on..)
Code for registering is as follows :
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
public Form1()
{
InitializeComponent();
RegisterHotKey(this.Handle, 1, 0, (int)Keys.A);
RegisterHotKey(this.Handle, 101, 4, (int)Keys.A);
}
Event handler(when the keys are pressed) :
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312)
{
switch (m.WParam.ToInt32())
{
case 1:
//add to a textbox
keypresstext.AppendText("a");
//unregister so the app doesnt rerecord it resulting in a loop
UnregisterHotKey(this.Handle, 1);
//send the key after intercepting
SendKeys.SendWait("a");
//reregister
RegisterHotKey(this.Handle, 1, 0,(int)Keys.A);
break;
case 101:
keypresstext.AppendText("A");
UnregisterHotKey(this.Handle, 101);
SendKeys.Send("+{a}");
RegisterHotKey(this.Handle, 101, 4, (int)Keys.A);
break;
}
}
base.WndProc(ref m);
}