예제 #1
0
파일: KeySend.cs 프로젝트: stuart2w/SAW
 /// <summary>Adds an event changing the state of the given key.  Only for low level use - usually use SendStringKeys</summary>
 public void AddKeyEvent(Keys key, bool down)
 {
     Windows.tagINPUT create = new Windows.tagINPUT(Windows.INPUTTYPE.KEYBOARD);
     create.union.ki.dwExtraInfo = UIntPtr.Zero;
     if (!down)
     {
         create.union.ki.dwFlags = Windows.KEYEVENTF.KEYUP;
     }
     if (key != Keys.Menu && key != Keys.ControlKey && m_AltMode == false)             // eKey <> Keys.LMenu And eKey <> Keys.RMenu
     {
         // must NOT be used when sending Alt codes.  But is required to make (eg) ctrl-shift-left work
         create.union.ki.dwFlags = create.union.ki.dwFlags | Windows.KEYEVENTF.EXTENDEDKEY;
     }
     create.union.ki.time  = 0;
     create.union.ki.wScan = (short)Windows.MapVirtualKey((uint)key, Windows.MAPVK_VK_TO_VSC);             // required to make Alt+NNNN work
     if (Switches.Switching.KeySwitch.KeyCurrentlyUsedForSwitching(key))
     {
         create.union.ki.wScan = 0;                 // the keyhook will ignore keys if the scan code is not set at all
     }
     create.union.ki.wVk = (short)key;
     Debug.WriteLine(key + " " + (down ? "down" : "up"));
     m_Output.Add(create);
 }