public void PressAndHold(KeysEx keyCode)
        {
            switch (keyCode)
            {
            case KeysEx.VK_LSHIFT:
            case KeysEx.VK_RSHIFT:
            case KeysEx.VK_SHIFT: this.Shift = !this.Shift; break;

            case KeysEx.VK_MENU: Alt = !Alt; break;

            case KeysEx.VK_CONTROL:
            case KeysEx.VK_RCONTROL:
            case KeysEx.VK_LCONTROL: this.Ctrl = !this.Ctrl; break;

            case KeysEx.VK_LWIN: this.Win = !this.Win; break;
            }

            //TODO: consider implementing collection of pressed keys
            // instead of handling all cases manually

            //VK keyCode = (VK)Enum.Parse(typeof(VK), key);
            //if (!pressedKeys.Keys.Contains(keyCode)) pressedKeys.Add(keyCode, false);
            //if (null==pressedKeys[keyCode]) ReleaseSticky(keyCode); else PressSticky(keyCode);
            //pressedKeys[keyCode] = !pressedKeys[keyCode];
        }
Beispiel #2
0
 internal KeyboardLayout(String layoutId, KeysEx specialShiftVk, VirtualKey[] keys, Dictionary <char, DeadKey> deadKeys)
 {
     this.layoutId       = layoutId;
     this.specialShiftVk = specialShiftVk;
     this.keys           = keys;
     this.deadKeys       = deadKeys;
 }
        void FindSpecialShiftState(IntPtr hkl, KeyboardLayoutContent kbl)
        {
            // See if there is a special shift state added
            for (KeysEx vk = KeysEx.None; vk <= KeysEx.Last; vk++)
            {
                uint sc  = NativeMethods.User32.MapVirtualKeyEx((uint)vk, 0, hkl);
                uint vkL = NativeMethods.User32.MapVirtualKeyEx(sc, 1, hkl);
                uint vkR = NativeMethods.User32.MapVirtualKeyEx(sc, 3, hkl);
                if (vkL != vkR && (uint)vk != vkL)
                {
                    switch (vk)
                    {
                    case KeysEx.VK_LCONTROL:
                    case KeysEx.VK_RCONTROL:
                    case KeysEx.VK_LSHIFT:
                    case KeysEx.VK_RSHIFT:
                    case KeysEx.VK_LMENU:
                    case KeysEx.VK_RMENU:
                        break;

                    default:
                        kbl.SpecialShiftVk = vk;
                        break;
                    }
                }
            }
        }
        public static string KeyCodeToUnicode(KeysEx key, bool shift, bool altGr)
        {
            byte[] keyboardState       = new byte[255];
            bool   keyboardStateStatus = GetKeyboardState(keyboardState);


            if (shift)
            {
                keyboardState[(int)KeysEx.VK_SHIFT] = 0xff;
            }
            if (altGr)
            {
                keyboardState[(int)KeysEx.VK_CONTROL] = 0xff;
                keyboardState[(int)KeysEx.VK_MENU]    = 0xff;
            }

            if (!keyboardStateStatus)
            {
                return("");
            }

            uint   virtualKeyCode        = (uint)key;
            IntPtr inputLocaleIdentifier = GetKeyboardLayout(0);
            uint   scanCode = MapVirtualKeyEx(virtualKeyCode, 0, inputLocaleIdentifier);

            StringBuilder result = new StringBuilder();

            ToUnicodeEx(virtualKeyCode, scanCode, keyboardState, result, (int)5, (uint)0, inputLocaleIdentifier);

            return(result.ToString());
        }
        public static string GetCharFromLayout(KeysEx keys, bool shift, bool altGr)
        {
            if (!isInit)
            {
                Init();
            }

            System.Text.StringBuilder sbString = new System.Text.StringBuilder(5);

            var buf           = new StringBuilder(256);
            var keyboardState = new byte[256];

            if (shift)
            {
                keyboardState[(int)KeysEx.VK_SHIFT] = 0xff;
            }
            if (altGr)
            {
                keyboardState[(int)KeysEx.VK_CONTROL] = 0xff;
                keyboardState[(int)KeysEx.VK_MENU]    = 0xff;
            }


            ToUnicodeEx((uint)keys, 0, keyboardState, buf, 256, 0, layout);
            return(buf.ToString());
        }
 internal KeyboardLayoutContent(String layoutId)
 {
     this.layoutId       = layoutId;
     this.specialShiftVk = KeysEx.None;
     this.keys           = new VirtualKeyContent[256];
     this.deadKeys       = null;
 }
Beispiel #7
0
 private void OnControlKeyEvent(KeysEx controlInputValue)
 {
     if (ControlKeyUp != null)
     {
         ControlKeyUp((int)controlInputValue);
     }
 }
Beispiel #8
0
        /// <summary>
        /// Determines whether the specified key, combined with all currently pressed modifier keys, matches this hook's key combination.
        /// </summary>
        /// <param name="unmodifiedKey">The unmodified key to combine with all currently pressed keyboard modifier keys.</param>
        /// <returns>True if unmodifiedKey matches Combination.UnmodifiedKey and all modifier keys contained in the
        /// Combination property are currently pressed; otherwise, false.</returns>
        protected bool CheckIsHookKeyCombination(KeysEx unmodifiedKey)
        {
            KeyCombination pressedKeyCombo = new KeyCombination(unmodifiedKey);

            if (IsKeyPressed(KeysEx.ControlKey))
            {
                pressedKeyCombo.Add(KeysEx.Control);
            }

            if (IsKeyPressed(KeysEx.ShiftKey))
            {
                pressedKeyCombo.Add(KeysEx.Shift);
            }

            if (IsKeyPressed(KeysEx.LMenu) || IsKeyPressed(KeysEx.RMenu))
            {
                pressedKeyCombo.Add(KeysEx.Alt);
            }

            if ((IsKeyPressed(KeysEx.LWin) || IsKeyPressed(KeysEx.RWin)))
            {
                pressedKeyCombo.Add(KeysEx.WinLogo);
            }

            return(Combination == pressedKeyCombo);
        }
Beispiel #9
0
 public KeyStats(string name, KeysEx keyCode, bool useShift = false, string capName = null, string shiftName = null)
 {
     Name      = name;
     KeyCode   = keyCode;
     UseShift  = useShift;
     ShiftName = string.IsNullOrEmpty(shiftName) ? string.IsNullOrEmpty(name) ? string.Empty : Name.ToLowerInvariant() : shiftName;
     CapName   = string.IsNullOrEmpty(capName) ? string.IsNullOrEmpty(name) ? string.Empty : Name.ToUpperInvariant() : capName;
 }
 public void PressAndReleaseKey(KeysEx keyCode)
 {
     SendInputs(new INPUT[]
     {
         CreateInputKey(keyCode, 0),
         CreateInputKey(keyCode, KEYBDINPUT_FLAGS.KEYEVENTF_KEYUP)
     });
 }
 private void OnControlKeyEvent(KeysEx controlInputValue)
 {
     if (ControlKeyUp != null)
     {
         UpdateKeyboardShift(ShiftState.ShiftUp);
         ControlKeyUp((int)controlInputValue);
     }
 }
Beispiel #12
0
		/// <summary>
		/// Raises the KeyboardLockDownKeyPressed event by invoking each subscribed delegate asynchronously.
		/// </summary>
		/// <param name="pressedKeys">The keys that are pressed.</param>
		/// <param name="state">The state of the keys.</param>
		static void OnLockedDownKeyboardKeyPressed(KeysEx pressedKeys, KeyState state)
		{
			foreach (EventHandler<KeyboardLockDownKeyPressedEventArgs> pressedEvent in LockedDownKeyboardKeyPressed.GetInvocationList())
			{
				var args = new KeyboardLockDownKeyPressedEventArgs(pressedKeys, state);
				AsyncCallback callback = ar => ((EventHandler<KeyboardLockDownKeyPressedEventArgs>)ar.AsyncState).EndInvoke(ar);
				pressedEvent.BeginInvoke(null, args, callback, pressedEvent);
			}
		}
Beispiel #13
0
 /// <summary>
 /// Raises the KeyboardLockDownKeyPressed event by invoking each subscribed delegate asynchronously.
 /// </summary>
 /// <param name="pressedKeys">The keys that are pressed.</param>
 /// <param name="state">The state of the keys.</param>
 static void OnLockedDownKeyboardKeyPressed(KeysEx pressedKeys, KeyState state)
 {
     foreach (EventHandler <KeyboardLockDownKeyPressedEventArgs> pressedEvent in LockedDownKeyboardKeyPressed.GetInvocationList())
     {
         var           args     = new KeyboardLockDownKeyPressedEventArgs(pressedKeys, state);
         AsyncCallback callback = ar => ((EventHandler <KeyboardLockDownKeyPressedEventArgs>)ar.AsyncState).EndInvoke(ar);
         pressedEvent.BeginInvoke(null, args, callback, pressedEvent);
     }
 }
        protected override KeyboardLayout Read(ContentReader input, KeyboardLayout existingInstance)
        {
            String layoutId       = input.ReadString();
            KeysEx specialShiftVk = (KeysEx)input.ReadUInt32();

            VirtualKey[] keys = ReadVirtualKeys(input);
            Dictionary <char, DeadKey> deadKeys = ReadDeadKeys(input);

            return(new KeyboardLayout(layoutId, specialShiftVk, keys, deadKeys));
        }
        /// <summary>
        /// Froms the string to keys.
        /// </summary>
        /// <param name="keys">The keys.</param>
        void FromStringToKeys(string keys)
        {
            IEnumerable <string> segments = keys.Split(new[] { '+' });

            foreach (string segment in segments)
            {
                string modifiedSegment = segment.ToLowerInvariant().Trim() == "ctrl" ? "Control" : segment;
                keyChain |= EnumParser.Parse <KeysEx>(modifiedSegment.Trim());
            }
        }
		public void PressAndRelease(KeysEx keyCode)
		{
			try
			{
				SendKey(keyCode);
			}
			catch
			{ }

			ReleaseStickyKeys();
		}
        public void PressAndRelease(KeysEx keyCode)
        {
            try
            {
                SendKey(keyCode);
            }
            catch
            { }

            ReleaseStickyKeys();
        }
Beispiel #18
0
        /// <summary>
        /// Returns a value indicating whether a non-modifier key is currently pressed.
        /// </summary>
        /// <param name="key">The key to check. Key must not be a modifier bit mask.</param>
        /// <returns>True if the key is currently pressed; otherwise false.</returns>
        /// <exception cref="ArgumentException">Occurs if key is a modifier bit mask. </exception>
        static bool IsKeyPressed(KeysEx key)
        {
            if ((key & KeysEx.Modifiers) == KeysEx.Modifiers)
            {
                throw new ArgumentException("Key cannot contain any modifiers.", "key");
            }

            const int keyPressed = NativeMethods.KeyStateConstants.KEY_PRESSED;

            return((NativeMethods.GetKeyState((int)key) & keyPressed) == keyPressed);
        }
Beispiel #19
0
 public KeyStats(string name, KeysEx keyCode, bool useShift = false, string capName = null)
 {
     Name      = name;
     KeyCode   = keyCode;
     UseShift  = useShift;
     ShiftName = string.Empty;
     CapName   = string.Empty;
     if (!string.IsNullOrEmpty(Name))
     {
         ShiftName = Name.ToLowerInvariant();
         CapName   = Name.ToUpperInvariant();
     }
 }
        /// <summary>
        /// Determines whether the specified key exists in this combination.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>True if the specified key exists; otherwise, false.</returns>
        public bool Contains(KeysEx key)
        {
            switch (key)
            {
            case KeysEx.Control:
            case KeysEx.Shift:
            case KeysEx.Alt:
            case KeysEx.WinLogo:
                return((keyChain & KeysEx.Modifiers) == key);

            default:
                return((keyChain & KeysEx.KeyCode) == key);
            }
        }
Beispiel #21
0
        /// <summary>
        /// Returns an array of values that correspond to the pressed keys,
        /// processed by this keyboard layout using the specified flags.
        /// </summary>
        /// <param name="state">The keyboard state to process.</param>
        /// <param name="flags">Flags.</param>
        /// <returns>The virtual key values.</returns>
        public VirtualKeyValue[] ProcessKeys(KeyboardState state, ProcessKeysFlags flags)
        {
            ShiftState shiftState =
                (state.IsKeyDown(XnaKeys.LeftShift) || state.IsKeyDown(XnaKeys.RightShift) ? ShiftState.Shft : 0) |
                (state.IsKeyDown(XnaKeys.LeftControl) || state.IsKeyDown(XnaKeys.RightControl) ? ShiftState.Ctrl : 0) |
                // FIXME: RightAlt may be specialShiftVk, even though ShiftState.Menu is not supported in keyboard layouts
                (state.IsKeyDown(XnaKeys.LeftAlt) || state.IsKeyDown(XnaKeys.RightAlt) ? ShiftState.Menu : 0) |
                // FIXME: ensure that XnaKeys == KeysEx
                (specialShiftVk != KeysEx.None ? state.IsKeyDown((XnaKeys)specialShiftVk) ? ShiftState.Spcl : 0 : 0);

            // Toggle caps lock state on first caps lock press
            if (capsPressed == false && state.IsKeyDown(XnaKeys.CapsLock) == true)
            {
                capsLocked = !capsLocked;
            }
            capsPressed = state.IsKeyDown(XnaKeys.CapsLock);
            bool applyCapsLock = (flags & ProcessKeysFlags.IgnoreCapsLock) != 0 ? false : capsLocked;

#if IGNORED
            XnaKeys[] keys        = state.GetPressedKeys();
            KeysEx[]  pressedKeys = new KeysEx[keys.Length];
            // Filter out control keys
            int i = 0;
            foreach (XnaKeys key in keys)
            {
                VirtualKey vk = keys[(int)key];
                if (vk != null && char.IsControl(vk.GetShiftState(ShiftState.Base, false).Characters[0]) == false)
                {
                    //FIXME: ensure that XnaKeys == KeysEx
                    pressedKeys[i++] = (KeysEx)key;
                }
            }
#else
            XnaKeys[] pressedKeys = state.GetPressedKeys();
#endif
            List <VirtualKeyValue> res     = new List <VirtualKeyValue>(pressedKeys.Length);
            List <XnaKeys>         pressed = new List <Keys>();
            foreach (XnaKeys key in pressedKeys)
            {
                VirtualKey vk = keys[(int)key];
                if (vk != null)
                {
                    res.Add(vk.GetShiftState(shiftState, applyCapsLock));
                    pressed.Add(key);
                }
            }
            filteredPressedKeys = pressed.ToArray();
            return(res.ToArray());
        }
        /// <summary>
        /// Removes the specified key from this combination. Must be called once for each key to be removed.
        /// </summary>
        /// <param name="key">The key to remove.</param>
        public void Remove(KeysEx key)
        {
            if (Contains(key))
            {
                keyChain ^= key;
            }

            if (key == KeysEx.LWin || key == KeysEx.RWin)
            {
                if (Contains(KeysEx.WinLogo))
                {
                    keyChain ^= KeysEx.WinLogo;
                }
            }
        }
Beispiel #23
0
        /// <summary>
        /// Callback handler for keyboard lockdowns.
        /// </summary>
        static IntPtr LockdownHookCallBack(int nCode, IntPtr wParam, IntPtr lParam)
        {
            int    keyStateParam = (int)wParam;
            KeysEx pressedKey    = (KeysEx)Marshal.ReadInt32(lParam);

            switch (pressedKey)
            {
            case KeysEx.LControlKey:
            case KeysEx.RControlKey:
                pressedKey = KeysEx.Control;
                break;

            case KeysEx.RMenu:
            case KeysEx.LMenu:
                pressedKey = KeysEx.Alt;
                break;

            case KeysEx.LShiftKey:
            case KeysEx.RShiftKey:
                pressedKey = KeysEx.Shift;
                break;

            case KeysEx.LWin:
            case KeysEx.RWin:
                pressedKey = KeysEx.WinLogo;
                break;
            }

            KeyState keyState;

            if (keyStateParam == keyUp || keyStateParam == systemKeyUp)
            {
                keyState        = KeyState.Up;
                lockedDownKeys ^= pressedKey;
            }
            else if (keyStateParam == keyDown || keyStateParam == systemKeyDown)
            {
                keyState        = KeyState.Down;
                lockedDownKeys |= pressedKey;
            }
            else
            {
                throw new ArgumentOutOfRangeException("wParam", "Invalid key state detected.");
            }

            OnLockedDownKeyboardKeyPressed(lockedDownKeys, keyState);
            return(new IntPtr(1));
        }
        public void PressKey(KeysEx keyCode)
        {
            uint  intReturn = 0;
            INPUT structInput;

            structInput                = new INPUT();
            structInput.type           = (uint)1;
            structInput.ki.wScan       = 0;
            structInput.ki.time        = 0;
            structInput.ki.dwFlags     = 0;
            structInput.ki.dwExtraInfo = 0;
            // Key down the actual key-code

            structInput.ki.wVk = (ushort)keyCode;             //KeysEx.SHIFT etc.
            intReturn          = NativeWin32.SendInput(1, ref structInput, Marshal.SizeOf(structInput));
        }
Beispiel #25
0
        /// <summary>
        /// Determines whether this enumeration contains the Control modifier.
        /// </summary>
        /// <param name="keys">The keys to check for the Control modifier.</param>
        /// <returns>True if this enumeration contains the Control modifier; otherwise false.</returns>
        static bool IsControlModified(KeysEx keys)
        {
            if ((keys & KeysEx.Control) == KeysEx.Control)
                return true;

            KeysEx keyCode = keys & KeysEx.KeyCode;
            switch (keyCode)
            {
                case KeysEx.ControlKey:
                case KeysEx.LControlKey:
                case KeysEx.RControlKey:
                    return true;
            }

            return false;
        }
Beispiel #26
0
        /// <summary>
        /// Determines whether this enumeration contains the Alt modifier.
        /// </summary>
        /// <param name="keys">The keys to check for the Alt modifier.</param>
        /// <returns>True if this enumeration contains the Alt modifier; otherwise false.</returns>
        static bool IsAltModified(KeysEx keys)
        {
            if ((keys & KeysEx.Alt) == KeysEx.Alt)
                return true;

            KeysEx keyCode = keys & KeysEx.KeyCode;
            switch (keyCode)
            {
                case KeysEx.Menu:
                case KeysEx.LMenu:
                case KeysEx.RMenu:
                    return true;
            }

            return false;
        }
        /// <summary>
        /// Adds the specified keys to this combination. Note that a combination can only contain a single
        /// non-modifier key. If one already exists, it will be overwritten.
        /// </summary>
        /// <param name="keys">The keys to add.</param>
        public void Add(KeysEx keys)
        {
            KeysEx keyCode = keys & KeysEx.KeyCode;

            if (keyCode != KeysEx.None)
            {
                keyChain = keyCode | keyChain & KeysEx.Modifiers;
            }

            KeysEx modifiers = keys & KeysEx.Modifiers;

            if (modifiers != KeysEx.None)
            {
                keyChain = modifiers | keyChain & KeysEx.KeyCode | keyChain & KeysEx.Modifiers;
            }
        }
 private INPUT CreateInputKey(KeysEx keyCode, KEYBDINPUT_FLAGS dwFlags)
 {
     return(new INPUT()
     {
         type = INPUT_TYPE.INPUT_KEYBOARD,
         u = new InputUnion
         {
             ki = new KEYBDINPUT
             {
                 wVk = (System.UInt16)keyCode,
                 wScan = 0,
                 dwFlags = dwFlags,
                 dwExtraInfo = NativeWin32.GetMessageExtraInfo()
             }
         }
     });
 }
        public void ReleaseKey(KeysEx keyCode)
        {
            uint  intReturn = 0;
            INPUT structInput;

            structInput                = new INPUT();
            structInput.type           = (uint)1;
            structInput.ki.wScan       = 0;
            structInput.ki.time        = 0;
            structInput.ki.dwFlags     = 0;
            structInput.ki.dwExtraInfo = 0;

            // Key up the actual key-code
            structInput.ki.dwFlags = NativeWin32.KEYEVENTF_KEYUP;
            structInput.ki.wVk     = (ushort)keyCode;        // (ushort)NativeWin32.KeysEx.SNAPSHOT;//vk;
            intReturn = NativeWin32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput));
        }
Beispiel #30
0
        public static void DumpScanCodesVirtualKeys(String kid)
        {
            IntPtr hkl = NativeMethods.User32.LoadKeyboardLayout(kid, NativeMethods.User32.KLF_NOTELLSHELL);

            if (hkl == IntPtr.Zero)
            {
                Console.WriteLine("Sorry, that keyboard does not seem to be valid.");
            }
            else
            {
                int         nLCID = int.Parse(kid, NumberStyles.HexNumber);
                CultureInfo ci    = new System.Globalization.CultureInfo(nLCID & 0xFFFF);
                Console.WriteLine("{0}, {1}, {2}\n", ci.Name, ci.DisplayName, ci.EnglishName);

                Console.WriteLine("VK\tSC");
                Console.WriteLine("------------");
                for (KeysEx vk = KeysEx.None; vk <= KeysEx.Last; vk++)
                {
                    uint sc = NativeMethods.User32.MapVirtualKeyEx((uint)vk, 0, hkl);
                    Console.WriteLine("{0}\t{1}", vk, sc);
                }

                Console.WriteLine("\nSC\tVK");
                Console.WriteLine("------------");
                for (KeysEx vk = KeysEx.None; vk <= KeysEx.Last; vk++)
                {
                    uint sc = NativeMethods.User32.MapVirtualKeyEx((uint)vk, 0, hkl);
                    Console.WriteLine("{1}\t{0}", vk, sc);
                }

                InputLanguageCollection ilc = InputLanguage.InstalledInputLanguages;
                foreach (InputLanguage il in ilc)
                {
                    if (hkl == il.Handle)
                    {
                        hkl = IntPtr.Zero;
                        break;
                    }
                }
                if (hkl != IntPtr.Zero)
                {
                    NativeMethods.User32.UnloadKeyboardLayout(hkl);
                }
            }
        }
Beispiel #31
0
        /// <summary>
        /// Determines whether the specified keys contains the WinLogo modifier, the LWin key, or the RWin key.
        /// </summary>
        /// <param name="keys">The keys to check for logo key modifiers.</param>
        /// <returns>True if this instance contains a logo key modifier; otherwise, false.</returns>
        static bool IsWinLogoModified(KeysEx keys)
        {
            if ((keys & KeysEx.WinLogo) == KeysEx.WinLogo)
            {
                return(true);
            }

            KeysEx keyCode = keys & KeysEx.KeyCode;

            switch (keyCode)
            {
            case KeysEx.LWin:
            case KeysEx.RWin:
                return(true);
            }

            return(false);
        }
Beispiel #32
0
        /// <summary>
        /// Returns KeyCode portion of this instance. That is, the key stripped of modifiers.
        /// </summary>
        /// <param name="keys">The keys to remove modifier keys from.</param>
        static string UnmodifiedKey(KeysEx keys)
        {
            KeysEx keyCode = keys & KeysEx.KeyCode;

            switch (keyCode)
            {
            case KeysEx.Menu:
            case KeysEx.LMenu:
            case KeysEx.RMenu:
            case KeysEx.ShiftKey:
            case KeysEx.LShiftKey:
            case KeysEx.RShiftKey:
            case KeysEx.ControlKey:
            case KeysEx.LControlKey:
            case KeysEx.RControlKey:
            case KeysEx.LWin:
            case KeysEx.RWin:
                return(string.Empty);
            }

            switch (keyCode)
            {
            case KeysEx.D0:
            case KeysEx.D1:
            case KeysEx.D2:
            case KeysEx.D3:
            case KeysEx.D4:
            case KeysEx.D5:
            case KeysEx.D6:
            case KeysEx.D7:
            case KeysEx.D8:
            case KeysEx.D9:
                return(keyCode.ToString().Remove(0, 1));
            }

            if (keyCode.ToString().ToUpperInvariant().StartsWith("OEM"))
            {
                const uint convertToChar = 2;
                uint       keyLiteral    = NativeMethods.MapVirtualKey((uint)keyCode, convertToChar);
                return(Convert.ToChar(keyLiteral).ToString(CultureInfo.InvariantCulture));
            }

            return(keyCode.ToString());
        }
Beispiel #33
0
        /// <summary>
        /// Determines whether this enumeration contains the Control modifier.
        /// </summary>
        /// <param name="keys">The keys to check for the Control modifier.</param>
        /// <returns>True if this enumeration contains the Control modifier; otherwise false.</returns>
        static bool IsControlModified(KeysEx keys)
        {
            if ((keys & KeysEx.Control) == KeysEx.Control)
            {
                return(true);
            }

            KeysEx keyCode = keys & KeysEx.KeyCode;

            switch (keyCode)
            {
            case KeysEx.ControlKey:
            case KeysEx.LControlKey:
            case KeysEx.RControlKey:
                return(true);
            }

            return(false);
        }
Beispiel #34
0
        /// <summary>
        /// Determines whether this enumeration contains the Shift modifier.
        /// </summary>
        /// <param name="keys">The keys to check for the Shift modifier.</param>
        /// <returns>True if this enumeration contains the Shift modifier; otherwise false.</returns>
        static bool IsShiftModified(KeysEx keys)
        {
            if ((keys & KeysEx.Shift) == KeysEx.Shift)
            {
                return(true);
            }

            KeysEx keyCode = keys & KeysEx.KeyCode;

            switch (keyCode)
            {
            case KeysEx.ShiftKey:
            case KeysEx.LShiftKey:
            case KeysEx.RShiftKey:
                return(true);
            }

            return(false);
        }
		public void PressAndHold(KeysEx keyCode)
		{
			switch (keyCode)
			{
				case KeysEx.VK_LSHIFT:
				case KeysEx.VK_RSHIFT:
				case KeysEx.VK_SHIFT: this.Shift = !this.Shift; break;
				case KeysEx.VK_MENU: Alt = !Alt; break;
				case KeysEx.VK_CONTROL:
				case KeysEx.VK_RCONTROL:
				case KeysEx.VK_LCONTROL: this.Ctrl = !this.Ctrl; break;
				case KeysEx.VK_LWIN: this.Win = !this.Win; break;
			}

			//TODO: consider implementing collection of pressed keys
			// instead of handling all cases manually

			//VK keyCode = (VK)Enum.Parse(typeof(VK), key);
			//if (!pressedKeys.Keys.Contains(keyCode)) pressedKeys.Add(keyCode, false);
			//if (null==pressedKeys[keyCode]) ReleaseSticky(keyCode); else PressSticky(keyCode);
			//pressedKeys[keyCode] = !pressedKeys[keyCode];
		}
Beispiel #36
0
		/// <summary>
		/// Determines whether the specified key, combined with all currently pressed modifier keys, matches this hook's key combination.
		/// </summary>
		/// <param name="unmodifiedKey">The unmodified key to combine with all currently pressed keyboard modifier keys.</param>
		/// <returns>True if unmodifiedKey matches Combination.UnmodifiedKey and all modifier keys contained in the 
		/// Combination property are currently pressed; otherwise, false.</returns>
		protected bool CheckIsHookKeyCombination(KeysEx unmodifiedKey)
		{
			KeyCombination pressedKeyCombo = new KeyCombination(unmodifiedKey);

			if (IsKeyPressed(KeysEx.ControlKey))
				pressedKeyCombo.Add(KeysEx.Control);

			if (IsKeyPressed(KeysEx.ShiftKey))
				pressedKeyCombo.Add(KeysEx.Shift);

			if (IsKeyPressed(KeysEx.LMenu) || IsKeyPressed(KeysEx.RMenu))
				pressedKeyCombo.Add(KeysEx.Alt);

			if ((IsKeyPressed(KeysEx.LWin) || IsKeyPressed(KeysEx.RWin)))
				pressedKeyCombo.Add(KeysEx.WinLogo);

			return Combination == pressedKeyCombo;
		}
Beispiel #37
0
        static void Main(string[] args)
        {
            const string sBanner = "/*\r\n\r\n" +
              "This include file for Password Safe support of all keyboards supported\r\n" +
              "by Windows was created by the \"Password Safe - Keyboard Data Generator\" program\r\n" +
              "kblgen V{0} on a Windows 7 64-bit RC system with all keyboard layouts installed on\r\n" +
              "{1:u}.\r\n\r\n" +
              "The \"Password Safe - Keyboard Data Generator\" program is a modified version of\r\n" +
              "code published by Michael Kaplan in his series of MSDN Blogs \"Sorting it all Out,\r\n" +
              "Getting all you can out of a keyboard layout\" (Part 0 to Part 9b) between \r\n" +
              "March 23 and April 13, 2006.\r\n\r\n" +
              "See http://blogs.msdn.com/michkap/archive/2006/04/13/575500.aspx\r\n\r\n" +
              "  *** PLEASE DO NOT EDIT THIS FILE DIRECTLY ***\r\n\r\n" +
              "*/\r\n";
              string version = Application.ProductVersion;

              List<kbd_layout> kbd_layout_list = new List<kbd_layout>();
              GetKeyboardsOnMachine(ref kbd_layout_list);

              int cKeyboards = GetKeyboardLayoutList(0, null);
              IntPtr[] rghkl = new IntPtr[cKeyboards];
              GetKeyboardLayoutList(cKeyboards, rghkl);

              DateTime dateTime = DateTime.Now;

              CultureInfo cultureInfo   = Thread.CurrentThread.CurrentCulture;
              TextInfo textInfo = cultureInfo.TextInfo;

              List<string> Char_List = new List<string>();
              List<int> Char_Use_Count = new List<int>();
              List<string> Multi2Char_List = new List<string>();
              List<int> Multi2Char_Use_Count = new List<int>();
              List<string> Multi3Char_List = new List<string>();
              List<int> Multi3Char_Use_Count = new List<int>();
              List<string> Multi4Char_List = new List<string>();
              List<int> Multi4Char_Use_Count = new List<int>();
              List<char> DeadKey_List = new List<char>();
              List<int> DeadKey_Use_Count = new List<int>();
              List<string> KLID_Exclude_List = new List<string>();

              // The first four handled specially via XML
              KLID_Exclude_List.Add("00000404");  // Chinese (Simplified)
              KLID_Exclude_List.Add("00000411");  // Japanese
              KLID_Exclude_List.Add("00000412");  // Korean
              KLID_Exclude_List.Add("00000804");  // Chinese (Traditional)

              // Can't display characters using MS Arial Unicode font
              KLID_Exclude_List.Add("0000045A");  // Syriac
              KLID_Exclude_List.Add("00000465");  // Divehi Phonetic
              KLID_Exclude_List.Add("00010465");  // Divehi Typewriter

              // Not shown on MS web page of Keyboard Layouts (although in Vista/Windows 7)
              KLID_Exclude_List.Add("0000042F");  // Macedonian (Fyrom)
              KLID_Exclude_List.Add("0000044C");  // Malayalam
              KLID_Exclude_List.Add("0000044D");  // Assamese - INSCRIPT
              KLID_Exclude_List.Add("00000453");  // Khmer
              KLID_Exclude_List.Add("00000454");  // Lao
              KLID_Exclude_List.Add("0000045B");  // Sinhala
              KLID_Exclude_List.Add("00000461");  // Nepali
              KLID_Exclude_List.Add("00000463");  // Pashto (Afghanistan)
              KLID_Exclude_List.Add("0000046D");  // Bashkir
              KLID_Exclude_List.Add("0000046E");  // Luxembourgish
              KLID_Exclude_List.Add("0000046F");  // Greenlandic
              KLID_Exclude_List.Add("00000480");  // Uighur
              KLID_Exclude_List.Add("00000485");  // Yakut
              KLID_Exclude_List.Add("00000850");  // Mongolian (Mongolian Script)
              KLID_Exclude_List.Add("0000085D");  // Inuktitut - Latin
              KLID_Exclude_List.Add("00010416");  // Portuguese (Brazilian Abnt2)
              KLID_Exclude_List.Add("0001042E");  // Sorbian Extended
              KLID_Exclude_List.Add("0001042F");  // Macedonian (Fyrom) - Standard
              KLID_Exclude_List.Add("0001045A");  // Syriac Phonetic
              KLID_Exclude_List.Add("0001045B");  // Sinhala - wij
              KLID_Exclude_List.Add("0001045D");  // Inuktitut - Naqittaut
              KLID_Exclude_List.Add("00010401");  // Arabic (102)
              KLID_Exclude_List.Add("00020401");  // Arabic (102) AZERTY
              KLID_Exclude_List.Add("00020402");  // Bulgarian (Phonetic Layout)

              // Others
              KLID_Exclude_List.Add("0000043A");  // Maltese 47-Key
              KLID_Exclude_List.Add("0001043A");  // Maltese 48-Key
              KLID_Exclude_List.Add("00000451");  // Tibetan (Prc)
              KLID_Exclude_List.Add("00000C04");  // Chinese (Traditional, Hong Kong S.A.R.) - US Keyboard
              KLID_Exclude_List.Add("00001004");  // Chinese (Simplified, Singapore) - US Keyboard
              KLID_Exclude_List.Add("00001404");  // Chinese (Traditional, Macao S.A.R.) - Us Keyboard

              // Don't support Dvorak keyboard
              KLID_Exclude_List.Add("00010409");  // United States-Dvorak
              KLID_Exclude_List.Add("00030409");  // United States-Dvorak for left hand
              KLID_Exclude_List.Add("00040409");  // United States-Dvorak for right hand
              KLID_Exclude_List.Add("00050409");  // US English Table for IBM Arabic 238_L

              const int IDS_PHYSICAL = 8200;
              const int IDS_BASE = IDS_PHYSICAL + 1;
              string strKorean = "00000000";
              string strJapanese = "00000000";
              int max_rows = 0;
              int iCountMain = 0;
              int iCount = 0;
              int inumKLID2MC2 = 0;
              int inumKLID2MC3 = 0;
              int inumKLID2MC4 = 0;
              int iCountMC2 = 0;
              int iCountMC3 = 0;
              int iCountMC4 = 0;
              int iCountDK = -1;
              int iMC2_Offset = -1;
              int iMC3_Offset = -1;
              int iMC4_Offset = -1;
              int iDK_Offset = -1;
              // Initialise Char_List with most used entry
              // NOTE: This MUST be the first entry as offset == 0 is used in the DLL
              // to determine is there are any valid characters to be displayed in
              // this quartet
              int iOffset = 0;
              Char_List.Add(" 0x0000, 0x0000, 0x0000, 0x0000");
              Char_Use_Count.Add(0);

              StreamWriter sw_log = new StreamWriter("log.txt");

              StreamWriter sw_OSK_KLID2VKBDX_Table = new StreamWriter("OSK_KLID2VKBDX_Table.inc");
              sw_OSK_KLID2VKBDX_Table.WriteLine(sBanner, version, dateTime);
              string Cmd_arg = "";
              bool bAll = false, bXML_Only = false;
              sw_OSK_KLID2VKBDX_Table.WriteLine("static const st_IKLID2VKBD IKLID2VKBD[] = {");
              if (args.Length > 0) {
            Cmd_arg = args[0].ToUpper();
            if (Cmd_arg.CompareTo("ALL") == 0)
              bAll = true;
            else if (Cmd_arg.CompareTo("XML-ONLY") == 0) {
              bXML_Only = true;
              kbd_layout_list.Clear();
            }
              }
              if (Cmd_arg.Length > 0 && !bAll && !bXML_Only) {
            sw_OSK_KLID2VKBDX_Table.WriteLine("  {{0x{0}, &VKBD_{0}}},  // {1,4}", Cmd_arg, iCountMain);
            iCountMain++;
              } else {
            int i = -1;
            foreach (kbd_layout kbl in kbd_layout_list) {
              i++;
              // Exclude Dvorak keyboard or those requiring an IME + a few others
              // Unless command argument 'all' specified
              if (!bAll && KLID_Exclude_List.Contains(kbl.Key))
            continue;

              sw_OSK_KLID2VKBDX_Table.WriteLine("  {{0x{0}, &VKBD_{0}}},  // {1,4}", kbl.Key,
                                            iCountMain);
              iCountMain++;
            }
              }

              StreamWriter sw_OSK_KB_Data = new StreamWriter("OSK_KB_Data.inc");
              sw_OSK_KB_Data.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_KB_KLID2SCSS2MC2Data = new StreamWriter("OSK_KB_KLID2SCSS2MC2Data.inc");
              sw_OSK_KB_KLID2SCSS2MC2Data.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_KB_KLID2SCSS2MC3Data = new StreamWriter("OSK_KB_KLID2SCSS2MC3Data.inc");
              sw_OSK_KB_KLID2SCSS2MC3Data.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_KB_KLID2SCSS2MC4Data = new StreamWriter("OSK_KB_KLID2SCSS2MC4Data.inc");
              sw_OSK_KB_KLID2SCSS2MC4Data.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_KB_SCSS2MC2Data = new StreamWriter("OSK_KB_SCSS2MC2Data.inc");
              sw_OSK_KB_SCSS2MC2Data.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_KB_SCSS2MC3Data = new StreamWriter("OSK_KB_SCSS2MC3Data.inc");
              sw_OSK_KB_SCSS2MC3Data.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_KB_SCSS2MC4Data = new StreamWriter("OSK_KB_SCSS2MC4Data.inc");
              sw_OSK_KB_SCSS2MC4Data.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_Define_DeadKey_DataMaps = new StreamWriter("OSK_Define_DeadKey_DataMaps.inc");
              sw_OSK_Define_DeadKey_DataMaps.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_Insert_DeadKey_DataMaps = new StreamWriter("OSK_Insert_DeadKey_DataMaps.inc");
              sw_OSK_Insert_DeadKey_DataMaps.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_OSK_DeadKey_Data = new StreamWriter("OSK_DeadKey_Data.inc");
              sw_OSK_DeadKey_Data.WriteLine(sBanner, version, dateTime);

              StreamWriter sw_VKresource = new StreamWriter("VKresource3.inc");
              sw_VKresource.WriteLine(sBanner, version, dateTime);

              sw_VKresource.WriteLine("#define IDS_VKB_PHYSICAL                {0,4}\r\n",
                                  IDS_PHYSICAL);
              sw_VKresource.WriteLine("#define IDS_VKB_BASE                    {0,4}\r\n",
                                  IDS_PHYSICAL + 1);

              StreamWriter sw_VKPasswordSafe3 = new StreamWriter("VKPasswordSafe3.inc");
              sw_VKPasswordSafe3.WriteLine(sBanner, version, dateTime);

              sw_OSK_KB_KLID2SCSS2MC2Data.WriteLine("\r\nstatic const st_IKLID2SCSS2MC MC2[] = {");
              sw_OSK_KB_KLID2SCSS2MC3Data.WriteLine("\r\nstatic const st_IKLID2SCSS2MC MC3[] = {");
              sw_OSK_KB_KLID2SCSS2MC4Data.WriteLine("\r\nstatic const st_IKLID2SCSS2MC MC4[] = {");

              foreach (kbd_layout kbl in kbd_layout_list) {
            if (!bAll && Cmd_arg.Length > 0 && Cmd_arg != kbl.Key) {
              continue;
            } else {
              // Don't include excluded keyboards
              if (!bAll && KLID_Exclude_List.Contains(kbl.Key))
            continue;
            }

            IntPtr hkl = LoadKeyboardLayout(kbl.Key, KLF_NOTELLSHELL);
            if (iCount % 10 == 0)
              sw_VKPasswordSafe3.WriteLine("\r\nSTRINGTABLE\r\nBEGIN");
            if (iCount == 0)
              sw_VKPasswordSafe3.WriteLine("  IDS_VKB_PHYSICAL        \"- Physical -\"");

            Console.WriteLine("Processing Keyboard Layout - {0}:{1}", kbl.Key, kbl.Name);
            sw_log.WriteLine("Processing Keyboard Layout - {0}:{1}", kbl.Key, kbl.Name);

            sw_OSK_KB_Data.WriteLine("// Keyboard Layouts - {0}:{1}", kbl.Key, kbl.Name);
            sw_OSK_KB_Data.WriteLine("static st_IVKBD VKBD_{0} = {{", kbl.Key);
            int ires = IDS_BASE + iCount;
            sw_VKresource.WriteLine("#define IDS_VKB_{0}                {1,4}",
                                kbl.Key, ires);
            sw_VKPasswordSafe3.WriteLine("  IDS_VKB_{0}        \"{1}\"",
                                     kbl.Key, kbl.Name);
            iCount++;

            if (iCount % 10 == 0)
              sw_VKPasswordSafe3.WriteLine("END");

            Loader.RCtrlVk = KeysEx.None;

            KeysEx[] lpKeyState = new KeysEx[256];
            VirtualKey[] rgKey = new VirtualKey[256];
            List<DeadKey> alDead = new List<DeadKey>();

            // Scroll through the Scan Code (SC) values and get the valid Virtual Key (VK)
            // values in it. Then, store the SC in each valid VK so it can act as both a
            // flag that the VK is valid, and it can store the SC value.
            for (uint sc = 0x01; sc <= 0x7f; sc++) {
              VirtualKey key = new VirtualKey(hkl, sc);
              if (key.VK != 0) {
            rgKey[(uint)key.VK] = key;
              }
            }

            // add the special keys that do not get added from the code above
            for (KeysEx ke = KeysEx.VK_NUMPAD0; ke <= KeysEx.VK_NUMPAD9; ke++) {
              rgKey[(uint)ke] = new VirtualKey(hkl, ke);
            }

            rgKey[(uint)KeysEx.VK_DIVIDE] = new VirtualKey(hkl, KeysEx.VK_DIVIDE);
            rgKey[(uint)KeysEx.VK_CANCEL] = new VirtualKey(hkl, KeysEx.VK_CANCEL);
            rgKey[(uint)KeysEx.VK_DECIMAL] = new VirtualKey(hkl, KeysEx.VK_DECIMAL);
            // See if there is a special shift state added
            for (KeysEx vk = KeysEx.None; vk <= KeysEx.VK_OEM_CLEAR; vk++) {
              uint sc = VirtualKey.MapVirtualKeyEx((uint)vk, 0, hkl);
              uint vkL = VirtualKey.MapVirtualKeyEx(sc, 1, hkl);
              uint vkR = VirtualKey.MapVirtualKeyEx(sc, 3, hkl);
              if ((vkL != vkR) && ((uint)vk != vkL)) {
            switch (vk) {
              case KeysEx.VK_LCONTROL:
              case KeysEx.VK_RCONTROL:
              case KeysEx.VK_LSHIFT:
              case KeysEx.VK_RSHIFT:
              case KeysEx.VK_LMENU:
              case KeysEx.VK_RMENU:
                break;
              default:
                Loader.RCtrlVk = vk;
                break;
            }
              }
            }

            for (uint iKey = 0; iKey < rgKey.Length; iKey++) {
              if (rgKey[iKey] != null) {
            StringBuilder sbBuffer;   // Scratchpad we use many places
            for (ShiftState ss = ShiftState.Base; ss <= Loader.MaxShiftState; ss++) {
              if (ss == ShiftState.Menu || ss == ShiftState.ShftMenu) {
                // Alt and Shift+Alt don't work, so skip them
                continue;
              }
              for (int caps = 0; caps <= 1; caps++) {
                ClearKeyboardBuffer((uint)KeysEx.VK_DECIMAL, rgKey[(uint)KeysEx.VK_DECIMAL].SC, hkl);
                FillKeyState(lpKeyState, ss, (caps!= 0));
                sbBuffer = new StringBuilder(10);
                int rc = ToUnicodeEx((uint)rgKey[iKey].VK, rgKey[iKey].SC,
                                     lpKeyState, sbBuffer, sbBuffer.Capacity, 0, hkl);
                if (rc > 0) {
                  if (sbBuffer.Length == 0) {
                    // Someone defined NULL on the keyboard; let's coddle them
                    rgKey[iKey].SetShiftState(ss, "\u0000", false, (caps != 0));
                  } else {
                    if ((rc == 1) &&
                        (ss == ShiftState.LCtrl || ss == ShiftState.ShftLCtrl) &&
                        ((int)rgKey[iKey].VK == ((uint)sbBuffer[0] + 0x40))) {
                      // ToUnicodeEx has an internal knowledge about those
                      // VK_A ~ VK_Z keys to produce the control characters,
                      // when the conversion rule is not provided in keyboard
                      // layout files
                      continue;
                    }
                    rgKey[iKey].SetShiftState(ss, sbBuffer.ToString().Substring(0, rc), false, (caps != 0));
                  }
                } else if (rc < 0) {
                  rgKey[iKey].SetShiftState(ss, sbBuffer.ToString().Substring(0, 1), true, (caps != 0));
                  // It's a dead key; let's flush out whats stored in the keyboard state.
                  ClearKeyboardBuffer((uint)KeysEx.VK_DECIMAL, rgKey[(uint)KeysEx.VK_DECIMAL].SC, hkl);
                  DeadKey dk = null;
                  for (int iDead = 0; iDead < alDead.Count; iDead++) {
                    dk = (DeadKey)alDead[iDead];
                    if (dk.DeadCharacter == rgKey[iKey].GetShiftState(ss, caps != 0)[0]) {
                      break;
                    }
                    dk = null;
                  }
                  if (dk == null) {
                    alDead.Add(ProcessDeadKey(iKey, ss, lpKeyState, rgKey, caps == 1, hkl));
                  }
                }
              }
            }
              }
            }

            foreach (IntPtr i in rghkl) {
              if (hkl == i) {
            hkl = IntPtr.Zero;
            break;
              }
            }

            if (hkl != IntPtr.Zero) {
              UnloadKeyboardLayout(hkl);
            }

            // Okay, now we can dump the layout
            int numrows = 0;
            int inumMC2 = 0;
            int inumMC3 = 0;
            int inumMC4 = 0;

            for (uint iKey = 0; iKey < rgKey.Length; iKey++) {
              if (rgKey[iKey] == null ||
              rgKey[iKey].IsEmpty ||
              rgKey[iKey].VK == KeysEx.VK_CANCEL ||
              rgKey[iKey].VK == KeysEx.VK_BACK ||
              rgKey[iKey].VK == KeysEx.VK_TAB ||
              rgKey[iKey].VK == KeysEx.VK_RETURN ||
              rgKey[iKey].VK == KeysEx.VK_ESCAPE ||
              rgKey[iKey].VK == KeysEx.VK_MULTIPLY ||
              rgKey[iKey].VK == KeysEx.VK_ADD ||
              rgKey[iKey].VK == KeysEx.VK_SUBTRACT ||
              rgKey[iKey].VK == KeysEx.VK_DECIMAL ||
              rgKey[iKey].VK == KeysEx.VK_DIVIDE ||
              (rgKey[iKey].VK >= KeysEx.VK_NUMPAD0 &&
               rgKey[iKey].VK <= KeysEx.VK_NUMPAD9)) {
            continue;
              }
              numrows++;
            }
            max_rows = max_rows > numrows ? max_rows : numrows;
            sw_OSK_KB_Data.Write("  {0}, {1}", ires, numrows);

            for (uint iKey = 0; iKey < rgKey.Length; iKey++) {
              if (rgKey[iKey] == null ||
              rgKey[iKey].IsEmpty ||
              rgKey[iKey].VK == KeysEx.VK_CANCEL ||
              rgKey[iKey].VK == KeysEx.VK_BACK ||
              rgKey[iKey].VK == KeysEx.VK_TAB ||
              rgKey[iKey].VK == KeysEx.VK_RETURN ||
              rgKey[iKey].VK == KeysEx.VK_ESCAPE ||
              rgKey[iKey].VK == KeysEx.VK_MULTIPLY ||
              rgKey[iKey].VK == KeysEx.VK_ADD ||
              rgKey[iKey].VK == KeysEx.VK_SUBTRACT ||
              rgKey[iKey].VK == KeysEx.VK_DECIMAL ||
              rgKey[iKey].VK == KeysEx.VK_DIVIDE ||
              (rgKey[iKey].VK >= KeysEx.VK_NUMPAD0 &&
               rgKey[iKey].VK <= KeysEx.VK_NUMPAD9)) {
            continue;
              } else {
            int ichar1, ichar2, ichar3, ichar4;
            string header = rgKey[iKey].GetRowHeader;
            string chars1 = rgKey[iKey].Get_Standard_Chars1;
            ichar1 = Char_List.IndexOf(chars1);
            if (ichar1 == -1) {
              Char_List.Add(chars1);
              iOffset++;
              ichar1 = iOffset;
              Char_Use_Count.Add(1);
            } else
              Char_Use_Count[ichar1] = Char_Use_Count[ichar1] + 1;

            string chars2 = rgKey[iKey].Get_Standard_Chars2;
            ichar2 = Char_List.IndexOf(chars2);
            if (ichar2 == -1) {
              Char_List.Add(chars2);
              iOffset++;
              ichar2 = iOffset;
              Char_Use_Count.Add(1);
            } else
              Char_Use_Count[ichar2] = Char_Use_Count[ichar2] + 1;

            string chars3 = rgKey[iKey].Get_Standard_Chars3;
            ichar3 = Char_List.IndexOf(chars3);
            if (ichar3 == -1) {
              Char_List.Add(chars3);
              iOffset++;
              ichar3 = iOffset;
              Char_Use_Count.Add(1);
            } else
              Char_Use_Count[ichar3] = Char_Use_Count[ichar3] + 1;

            string chars4 = rgKey[iKey].Get_Standard_Chars4;
            ichar4 = Char_List.IndexOf(chars4);
            if (ichar4 == -1) {
              Char_List.Add(chars4);
              iOffset++;
              ichar4 = iOffset;
              Char_Use_Count.Add(1);
            } else
              Char_Use_Count[ichar4] = Char_Use_Count[ichar4] + 1;

            if (rgKey[iKey].Get_Multi_Chars_Count > 0) {
              List<st_multi_chars> Multi_Chars_List = rgKey[iKey].Get_Multi_Chars_List;
              for (int i = 0; i < Multi_Chars_List.Count; i++) {
                int index;
                switch (Multi_Chars_List[i].num) {
                  case 2:
                    if (inumMC2 == 0) {
                      sw_OSK_KB_KLID2SCSS2MC2Data.WriteLine(" {{ 0x{0}, &vctSCSS2MC2_{0} }},  // {1,4}",
                                                            kbl.Key, inumKLID2MC2);
                      sw_OSK_KB_SCSS2MC2Data.WriteLine("\r\nstatic const st_SCSS2Offset dtaSCSS2MC2_{0}[] = {{",
                                                       kbl.Key);
                      inumKLID2MC2++;
                    }

                    index = Multi2Char_List.IndexOf(Multi_Chars_List[i].mchars);
                    if (index == -1) {
                      Multi2Char_List.Add(Multi_Chars_List[i].mchars);
                      iMC2_Offset++;
                      index = iMC2_Offset;
                      iCountMC2++;
                      Multi2Char_Use_Count.Add(1);
                    } else {
                      Multi2Char_Use_Count[index] = Multi2Char_Use_Count[index] + 1;
                    }
                    sw_OSK_KB_SCSS2MC2Data.WriteLine(" {{ 0x{0:x4}, {1,3} }},  // {2,4}",
                                                     Multi_Chars_List[i].scss, index, inumMC2);
                    inumMC2++;
                    break;
                  case 3:
                    if (inumMC3 == 0) {
                      sw_OSK_KB_KLID2SCSS2MC3Data.WriteLine(" {{ 0x{0}, &vctSCSS2MC3_{0} }},  // {1,4}",
                                                            kbl.Key, inumKLID2MC3);
                      sw_OSK_KB_SCSS2MC3Data.WriteLine("\r\nstatic const st_SCSS2Offset dtaSCSS2MC3_{0}[] = {{",
                                                       kbl.Key);
                      inumKLID2MC3++;
                    }

                    index = Multi3Char_List.IndexOf(Multi_Chars_List[i].mchars);
                    if (index == -1) {
                      Multi3Char_List.Add(Multi_Chars_List[i].mchars);
                      iMC3_Offset++;
                      index = iMC3_Offset;
                      iCountMC3++;
                      Multi3Char_Use_Count.Add(1);
                    } else {
                      Multi3Char_Use_Count[index] = Multi3Char_Use_Count[index] + 1;
                    }
                    sw_OSK_KB_SCSS2MC3Data.WriteLine(" {{ 0x{0:x4}, {1,3} }},  // {2,4}",
                                                     Multi_Chars_List[i].scss, index, inumMC3);
                    inumMC3++;
                    break;
                  case 4:
                    if (inumMC4 == 0) {
                      sw_OSK_KB_KLID2SCSS2MC4Data.WriteLine(" {{ 0x{0}, &vctSCSS2MC4_{0} }}, // {1,4}",
                                                            kbl.Key, inumKLID2MC4);
                      sw_OSK_KB_SCSS2MC4Data.WriteLine("\r\nstatic const st_SCSS2Offset dtaSCSS2MC4_{0}[] = {{",
                                                       kbl.Key);
                      inumKLID2MC4++;
                    }

                    index = Multi4Char_List.IndexOf(Multi_Chars_List[i].mchars);
                    if (index == -1) {
                      Multi4Char_List.Add(Multi_Chars_List[i].mchars);
                      iMC4_Offset++;
                      index = iMC4_Offset;
                      iCountMC4++;
                      Multi4Char_Use_Count.Add(1);
                    } else {
                      Multi4Char_Use_Count[index] = Multi4Char_Use_Count[index] + 1;
                    }
                    sw_OSK_KB_SCSS2MC4Data.WriteLine(" {{ 0x{0:x4}, {1,3} }},  // {2,4}",
                                                     Multi_Chars_List[i].scss, index, inumMC4);
                    inumMC4++;
                    break;
                }
              }
            }
            sw_OSK_KB_Data.Write(",\r\n  {0} {1,4}, {2,4}, {3,4}, {4,4}", header, ichar1, ichar2, ichar3, ichar4);
              }
            }
            if (inumMC2 > 0) {
              sw_OSK_KB_SCSS2MC2Data.WriteLine("};\r\n");
              sw_OSK_KB_SCSS2MC2Data.WriteLine("static const Vct_ISCSS2MC vctSCSS2MC2_{0}(dtaSCSS2MC2_{0},", kbl.Key);
              sw_OSK_KB_SCSS2MC2Data.Write("                                               ");
              sw_OSK_KB_SCSS2MC2Data.WriteLine("dtaSCSS2MC2_{0} + {1});", kbl.Key, inumMC2);
            }

            if (inumMC3 > 0) {
              sw_OSK_KB_SCSS2MC3Data.WriteLine("};\r\n");
              sw_OSK_KB_SCSS2MC3Data.WriteLine("static const Vct_ISCSS2MC vctSCSS2MC3_{0}(dtaSCSS2MC3_{0},", kbl.Key);
              sw_OSK_KB_SCSS2MC3Data.Write("                                               ");
              sw_OSK_KB_SCSS2MC3Data.WriteLine("dtaSCSS2MC3_{0} + {1});", kbl.Key, inumMC3);
            }

            if (inumMC4 > 0) {
              sw_OSK_KB_SCSS2MC4Data.WriteLine("};\r\n");
              sw_OSK_KB_SCSS2MC4Data.WriteLine("static const Vct_ISCSS2MC vctSCSS2MC4_{0}(dtaSCSS2MC4_{0},", kbl.Key);
              sw_OSK_KB_SCSS2MC4Data.Write("                                               ");
              sw_OSK_KB_SCSS2MC4Data.WriteLine("dtaSCSS2MC4_{0} + {1});", kbl.Key, inumMC4);
            }

            if (alDead.Count > 0) {
              sw_OSK_Define_DeadKey_DataMaps.WriteLine("  static Map_IDK2SCSSCC m_map_IDK2SCSSCC_{0};", kbl.Key);
            }

            bool bFirst = alDead.Count > 0;
            foreach (DeadKey dk in alDead) {
              if (bFirst) {
            sw_OSK_DeadKey_Data.WriteLine("\r\n//\r\n// Keyboard {0} - {1} deadkeys\r\n//", kbl.Key, kbl.Name);
            sw_OSK_Insert_DeadKey_DataMaps.WriteLine("\r\n  m_mapIKLID2DK2SCSSCC.insert(std::make_pair(0x{0}, &m_map_IDK2SCSSCC_{0}));",
                                                    kbl.Key);
            bFirst = false;
              }

              char wcdk;
              int index;
              uint scss = 0;

              // Initialise enumerator
              dk.GetDeadKeyInfo(ref scss, out wcdk);
              sw_OSK_DeadKey_Data.WriteLine("\r\n// Deadkey 0x{0:x4}", ((ushort)dk.DeadCharacter).ToString("x4"));
              sw_OSK_DeadKey_Data.WriteLine("static const st_IDKSCSS2Offset dtaDeadkey_{0}_x{1}[{2}] = {{",
                                        kbl.Key, ((ushort)dk.DeadCharacter).ToString("x4"), dk.Count);

              int inumDK = 0;
              for (int id = 0; id < dk.Count; id++) {
            scss = 1;
            dk.GetDeadKeyInfo(ref scss, out wcdk);
            if (scss == 0)
              continue;

            iCountDK++;
            index = DeadKey_List.IndexOf(wcdk);
            if (index == -1) {
              DeadKey_List.Add(wcdk);
              iDK_Offset++;
              index = iDK_Offset;
              DeadKey_Use_Count.Add(1);
            } else {
              DeadKey_Use_Count[index] = DeadKey_Use_Count[index] + 1;
            }
            byte sc = (byte)((scss & 0xFF00) >> 8);
            byte ss = (byte)(scss & 0xFF);
            sw_OSK_DeadKey_Data.WriteLine("  {{ 0x{0:x2}, 0x{1:x2}, {2,4} }},  // {3,4}", sc, ss, index, inumDK++);
              }
              sw_OSK_DeadKey_Data.WriteLine("};\r\n");
              sw_OSK_DeadKey_Data.WriteLine("static const Vct_IDeadkeys vctDeadkey_{0}_x{1}(dtaDeadkey_{0}_x{1},", kbl.Key,
                                        ((ushort)dk.DeadCharacter).ToString("x4"));
              sw_OSK_DeadKey_Data.Write("                                                     ");
              sw_OSK_DeadKey_Data.WriteLine("dtaDeadkey_{0}_x{1} + {2});", kbl.Key,
                                        ((ushort)dk.DeadCharacter).ToString("x4"), dk.Count);
              sw_OSK_Insert_DeadKey_DataMaps.WriteLine("  m_map_IDK2SCSSCC_{0}.insert(std::make_pair(0x{1:x4}, &vctDeadkey_{0}_x{1}));",
                                                   kbl.Key, ((ushort)dk.DeadCharacter).ToString("x4"));
            }
            sw_OSK_KB_Data.WriteLine("\r\n};");
            sw_OSK_KB_Data.WriteLine();
              }

              // If caller specified a KLID - don't do XML as well
              if (Cmd_arg.Length > 0 && !bAll && !bXML_Only)
            goto finish_up;

              // Process XML Custom keyboards
              // Expects 2 files in this executable's directory:
              // user_keyboard.xml and user_keyboards.xsd
              // See these for details of their format
              if (!File.Exists("user_keyboards.xml") || !File.Exists("user_keyboards.xsd")) {
            sw_log.WriteLine("Either or both of the files 'user_keyboards.xml/xsd' are missing");
            sw_log.WriteLine("No processing of User Keyboards via a XML file will be performed.");
            goto finish_up;
              }

              ProcessXML xml_vld = new ProcessXML("user_keyboards.xsd");

              xml_vld.DoXML(true, "user_keyboards.xml");
              if (xml_vld.Results.Count > 0) {
            sw_log.WriteLine("Processing User Keyboards input via XML file encountered errors:");
            foreach (string res in xml_vld.Results) {
              sw_log.WriteLine("{0}", res);
            }
              }

              if (xml_vld.Results.Count == 0) {
            sw_log.WriteLine("Processing User Keyboards input via XML file:");
            xml_vld.DoXML(false, "user_keyboards.xml");

            foreach (st_XML_Keyboard xmlkbd in xml_vld.XMLKeyboards) {
              // Check unique
              kbd_layout kbl = new kbd_layout();
              string sKey = xmlkbd.KLID.ToUpper();
              string sName = xmlkbd.Name;
              if (kbd_layout_list.Exists(delegate(kbd_layout kblX)
                                     {return kblX.Key == sKey;})) {
            sw_log.WriteLine("Duplicate KLID '{0}' encountered. This keyboard has not been processed.", sKey);
            continue;
              }
              if (kbd_layout_list.Exists(delegate(kbd_layout kblX)
                                     {return kblX.Name == sName;})) {
            sw_log.WriteLine("Duplicate Keyboard Name '{0}' encountered. This keyboard has not been processed.", sName);
            continue;
              }
              kbl.Key = sKey;
              kbl.Name = sName;
              kbd_layout_list.Add(kbl);

              sw_OSK_KLID2VKBDX_Table.WriteLine("  {{0x{0}, &VKBD_{0}}},  // {1,4}", xmlkbd.KLID,
                                            iCountMain);
              iCountMain++;

              Console.WriteLine("Processing Keyboard Layout - {0}:{1}", xmlkbd.KLID, xmlkbd.Name);
              sw_log.WriteLine("Processing Keyboard Layout - {0}:{1}", xmlkbd.KLID, xmlkbd.Name);

              sw_OSK_KB_Data.WriteLine("// Keyboard Layouts - {0}:{1}", xmlkbd.KLID, xmlkbd.Name);
              sw_OSK_KB_Data.WriteLine("static st_IVKBD VKBD_{0} = {{", xmlkbd.KLID);
              int ires = IDS_BASE + iCount;
              sw_VKresource.WriteLine("#define IDS_VKB_{0}                {1,4}",
                                  xmlkbd.KLID, ires);
              sw_VKPasswordSafe3.WriteLine("  IDS_VKB_{0}        \"{1}\"",
                                     xmlkbd.KLID, xmlkbd.Name);
              // Remember 2 special keyboards for later
              if (xmlkbd.Name == "Korean")
            strKorean = xmlkbd.KLID;
              if (xmlkbd.Name == "Japanese")
            strJapanese = xmlkbd.KLID;
              iCount++;

              max_rows = max_rows > xmlkbd.KeyData.Count ? max_rows : xmlkbd.KeyData.Count;
              sw_OSK_KB_Data.Write("  {0}, {1}", ires, xmlkbd.KeyData.Count);
              for (int i = 0; i < xmlkbd.KeyData.Count; i++) {
            int ichar1, ichar2, ichar3, ichar4;
            ichar1 = Char_List.IndexOf(xmlkbd.KeyData[i].chars1);
            if (ichar1 == -1) {
              Char_List.Add(xmlkbd.KeyData[i].chars1);
              iOffset++;
              ichar1 = iOffset;
              Char_Use_Count.Add(1);
            } else
              Char_Use_Count[ichar1] = Char_Use_Count[ichar1] + 1;

            ichar2 = Char_List.IndexOf(xmlkbd.KeyData[i].chars2);
            if (ichar2 == -1) {
              Char_List.Add(xmlkbd.KeyData[i].chars2);
              iOffset++;
              ichar2 = iOffset;
              Char_Use_Count.Add(1);
            } else
              Char_Use_Count[ichar2] = Char_Use_Count[ichar2] + 1;

            ichar3 = Char_List.IndexOf(xmlkbd.KeyData[i].chars3);
            if (ichar3 == -1) {
              Char_List.Add(xmlkbd.KeyData[i].chars3);
              iOffset++;
              ichar3 = iOffset;
              Char_Use_Count.Add(1);
            } else
              Char_Use_Count[ichar3] = Char_Use_Count[ichar3] + 1;

            ichar4 = Char_List.IndexOf(xmlkbd.KeyData[i].chars4);
            if (ichar4 == -1) {
              Char_List.Add(xmlkbd.KeyData[i].chars4);
              iOffset++;
              ichar4 = iOffset;
              Char_Use_Count.Add(1);
            } else
              Char_Use_Count[ichar4] = Char_Use_Count[ichar4] + 1;

            sw_OSK_KB_Data.Write(",\r\n  0x" + xmlkbd.KeyData[i].sc + ",      0,");
            sw_OSK_KB_Data.Write(" {0,4}, {1,4}, {2,4}, {3,4}", ichar1, ichar2, ichar3, ichar4);
              }
              sw_OSK_KB_Data.WriteLine("\r\n};");
              sw_OSK_KB_Data.WriteLine();
            }
              }

              finish_up:
              sw_OSK_KLID2VKBDX_Table.WriteLine("};");

              if (iCountMC2 < 1)
            sw_OSK_KB_KLID2SCSS2MC2Data.WriteLine(" {0, NULL}  // Dummy");
              sw_OSK_KB_KLID2SCSS2MC2Data.WriteLine("};");

              if (iCountMC3 < 1)
            sw_OSK_KB_KLID2SCSS2MC3Data.WriteLine(" {0, NULL}  // Dummy");
              sw_OSK_KB_KLID2SCSS2MC3Data.WriteLine("};");

              if (iCountMC4 < 1)
            sw_OSK_KB_KLID2SCSS2MC4Data.WriteLine(" {0, NULL}  // Dummy");
              sw_OSK_KB_KLID2SCSS2MC4Data.WriteLine("};");

              // Write out the standard and extended arrays
              sw_OSK_KB_Data.WriteLine("static const wchar_t wc_Chars[{0}][4] = {{", iOffset + 1);
              for (int i = 0; i < iOffset; i++) {
            sw_OSK_KB_Data.WriteLine("  {{{0}}},  // {1,4}; Use Count = {2,5}",
                                 Char_List[i], i, Char_Use_Count[i]);
              }
              if (iOffset > 0)
            sw_OSK_KB_Data.WriteLine("  {{{0}}}   // {1,4}; Use Count = {2,5}",
                                 Char_List[iOffset], iOffset, Char_Use_Count[iOffset]);
              else
            sw_OSK_KB_Data.WriteLine("  {0, 0, 0, 0}   // Dummy");
              sw_OSK_KB_Data.WriteLine("};\r\n");

              int isize;
              isize = (iMC2_Offset) < 0 ? 1 : (iMC2_Offset + 1);

              sw_OSK_KB_SCSS2MC2Data.WriteLine("\r\nstatic const wchar_t wcMC2[{0}][2] = {{", isize);
              if (Multi2Char_List.Count > 0) {
            for (int i = 0; i < iMC2_Offset; i++) {
              sw_OSK_KB_SCSS2MC2Data.WriteLine("  {{{0}}},  // {1,4}; Use Count = {2,3}",
                                           Multi2Char_List[i], i, Multi2Char_Use_Count[i]);
            }
            sw_OSK_KB_SCSS2MC2Data.WriteLine("  {{{0}}}   // {1,4}; Use Count = {2,3}",
                                         Multi2Char_List[iMC2_Offset], iMC2_Offset,
                                         Multi2Char_Use_Count[iMC2_Offset]);
              } else {
            sw_OSK_KB_SCSS2MC2Data.WriteLine("  {0, 0}   // Dummy");
              }
              sw_OSK_KB_SCSS2MC2Data.WriteLine("};");

              isize = (iMC3_Offset) < 0 ? 1 : (iMC3_Offset + 1);
              sw_OSK_KB_SCSS2MC3Data.WriteLine("\r\nstatic const wchar_t wcMC3[{0}][3] = {{", isize);
              if (Multi3Char_List.Count > 0) {
            for (int i = 0; i < iMC3_Offset; i++) {
              sw_OSK_KB_SCSS2MC3Data.WriteLine("  {{{0}}},  // {1,4}; Use Count = {2,3}",
                                           Multi3Char_List[i], i, Multi3Char_Use_Count[i]);
            }
            sw_OSK_KB_SCSS2MC3Data.WriteLine("  {{{0}}}   // {1,4}; Use Count = {2,3}",
                                         Multi3Char_List[iMC3_Offset], iMC3_Offset,
                                         Multi3Char_Use_Count[iMC3_Offset]);
              } else {
            sw_OSK_KB_SCSS2MC3Data.WriteLine("  {0, 0, 0}   // Dummy");
              }
              sw_OSK_KB_SCSS2MC3Data.WriteLine("};");

              isize = (iMC4_Offset) < 0 ? 1 : (iMC4_Offset + 1);
              sw_OSK_KB_SCSS2MC4Data.WriteLine("\r\nstatic const wchar_t wcMC4[{0}][4] = {{", isize);
              if (Multi4Char_List.Count > 0) {
            for (int i = 0; i < iMC4_Offset; i++) {
              sw_OSK_KB_SCSS2MC4Data.WriteLine("  {{{0}}},  // {1,4}; Use Count = {2,3}",
                                           Multi4Char_List[i], i, Multi4Char_Use_Count[i]);
            }
            sw_OSK_KB_SCSS2MC4Data.WriteLine("  {{{0}}}   // {1,4}; Use Count = {2,3}",
                                         Multi4Char_List[iMC4_Offset], iMC4_Offset,
                                         Multi4Char_Use_Count[iMC4_Offset]);
              } else {
            sw_OSK_KB_SCSS2MC4Data.WriteLine("  {0, 0, 0, 0}   // Dummy");
              }
              sw_OSK_KB_SCSS2MC4Data.WriteLine("};");

              isize = (iDK_Offset) < 0 ? 1 : (iDK_Offset + 1);
              sw_OSK_DeadKey_Data.WriteLine("\r\nstatic const wchar_t wcDK[{0}] = {{", isize);

              if (DeadKey_List.Count > 0) {
            for (int i = 0; i < iDK_Offset; i++) {
              sw_OSK_DeadKey_Data.WriteLine("  {{ 0x{0:x4} }},  // {1,4}; Use Count = {2,3}",
                                       ((ushort)DeadKey_List[i]).ToString("x4"),
                                        i, DeadKey_Use_Count[i]);
            }
            sw_OSK_DeadKey_Data.WriteLine("  {{ 0x{0:x4} }}   // {1,4}; Use Count = {2,3}",
                                      ((ushort)DeadKey_List[iDK_Offset]).ToString("x4"),
                                      iDK_Offset, DeadKey_Use_Count[iDK_Offset]);
              } else {
            sw_OSK_DeadKey_Data.WriteLine("  {0}   // Dummy");
              }
              sw_OSK_DeadKey_Data.WriteLine("};");

              StreamWriter sw_OSK_voskeys = new StreamWriter("OSK_voskeys.inc");
              sw_OSK_voskeys.WriteLine(sBanner, version, dateTime);
              sw_OSK_voskeys.WriteLine("#define NUM_KEYBOARDS              {0,4}", iCount);
              sw_OSK_voskeys.WriteLine("#define MAX_ROWS                   {0,4}", max_rows);
              sw_OSK_voskeys.WriteLine();
              sw_OSK_voskeys.WriteLine("#define NUM_UNIQUE_SC              {0,4}", iOffset + 1);
              sw_OSK_voskeys.WriteLine("#define NUM_UNIQUE_MC2             {0,4}", iMC2_Offset + 1);
              sw_OSK_voskeys.WriteLine("#define NUM_UNIQUE_MC3             {0,4}", iMC3_Offset + 1);
              sw_OSK_voskeys.WriteLine("#define NUM_UNIQUE_MC4             {0,4}", iMC4_Offset + 1);
              sw_OSK_voskeys.WriteLine("#define NUM_UNIQUE_DK              {0,4}", iDK_Offset + 1);
              sw_OSK_voskeys.WriteLine();
              sw_OSK_voskeys.WriteLine("#define NUM_MC2                    {0,4}", inumKLID2MC2);
              sw_OSK_voskeys.WriteLine("#define NUM_MC3                    {0,4}", inumKLID2MC3);
              sw_OSK_voskeys.WriteLine("#define NUM_MC4                    {0,4}", inumKLID2MC4);
              sw_OSK_voskeys.WriteLine();
              sw_OSK_voskeys.WriteLine("#define KOREAN_KBD           0x" + strKorean);
              sw_OSK_voskeys.WriteLine("#define JAPANESE_KBD         0x" + strJapanese);

              if (iCount % 10 != 0)
            sw_VKPasswordSafe3.WriteLine("END");

              sw_VKresource.WriteLine();

              // Close files
              sw_OSK_KLID2VKBDX_Table.Close();
              sw_OSK_Define_DeadKey_DataMaps.Close();
              sw_OSK_Insert_DeadKey_DataMaps.Close();
              sw_OSK_DeadKey_Data.Close();

              sw_OSK_voskeys.Close();

              sw_OSK_KB_Data.Close();
              sw_OSK_KB_KLID2SCSS2MC2Data.Close();
              sw_OSK_KB_KLID2SCSS2MC3Data.Close();
              sw_OSK_KB_KLID2SCSS2MC4Data.Close();
              sw_OSK_KB_SCSS2MC2Data.Close();
              sw_OSK_KB_SCSS2MC3Data.Close();
              sw_OSK_KB_SCSS2MC4Data.Close();

              sw_VKPasswordSafe3.Close();
              sw_VKresource.Close();

              sw_log.Close();
        }
Beispiel #38
0
        /// <summary>
        /// Determines whether the specified keys contains the WinLogo modifier, the LWin key, or the RWin key.
        /// </summary>
        /// <param name="keys">The keys to check for logo key modifiers.</param>
        /// <returns>True if this instance contains a logo key modifier; otherwise, false.</returns>
        static bool IsWinLogoModified(KeysEx keys)
        {
            if ((keys & KeysEx.WinLogo) == KeysEx.WinLogo)
                return true;

            KeysEx keyCode = keys & KeysEx.KeyCode;
            switch (keyCode)
            {
                case KeysEx.LWin:
                case KeysEx.RWin:
                    return true;
            }

            return false;
        }
		public void PressKey(KeysEx keyCode)
		{
			uint intReturn = 0;
			INPUT structInput;
			structInput = new INPUT();
			structInput.type = (uint)1;
			structInput.ki.wScan = 0;
			structInput.ki.time = 0;
			structInput.ki.dwFlags = 0;
			structInput.ki.dwExtraInfo = 0;
			// Key down the actual key-code

			structInput.ki.wVk = (ushort)keyCode; //KeysEx.SHIFT etc.
			intReturn = NativeWin32.SendInput(1, ref structInput, Marshal.SizeOf(structInput));
		}
Beispiel #40
0
 // The keyboard layout
 private static DeadKey ProcessDeadKey(
     uint iKeyDead,              // The index into the VirtualKey of the dead key
     ShiftState shiftStateDead,  // The shiftstate that contains the dead key
     KeysEx[] lpKeyStateDead,    // The key state for the dead key
     VirtualKey[] rgKey,         // Our array of dead keys
     bool fCapsLock,             // Was the caps lock key pressed?
     IntPtr hkl)
 {
     KeysEx[] lpKeyState = new KeysEx[256];
       DeadKey deadKey = new DeadKey(rgKey[iKeyDead].GetShiftState(shiftStateDead, fCapsLock)[0]);
       for (uint iKey = 0; iKey < rgKey.Length; iKey++) {
     if (rgKey[iKey] != null) {
       StringBuilder sbBuffer = new StringBuilder(10);   // Scratchpad we use many places
       for (ShiftState ss = ShiftState.Base; ss <= Loader.MaxShiftState; ss++) {
     int rc = 0;
     if (ss == ShiftState.Menu || ss == ShiftState.ShftMenu) {
       // Alt and Shift+Alt don't work, so skip them
       continue;
     }
     for (int caps = 0; caps <= 1; caps++) {
       // First the dead key
       while (rc >= 0) {
         // We know that this is a dead key coming up, otherwise
         // this function would never have been called. If we do
         // *not* get a dead key then that means the state is
         // messed up so we run again and again to clear it up.
         // Risk is technically an infinite loop but per Hiroyama
         // that should be impossible here.
         rc = ToUnicodeEx((uint)rgKey[iKeyDead].VK, rgKey[iKeyDead].SC,
                          lpKeyStateDead, sbBuffer, sbBuffer.Capacity, 0, hkl);
       }
       // Now fill the key state for the potential base character
       FillKeyState(lpKeyState, ss, (caps != 0));
       sbBuffer = new StringBuilder(10);
       rc = ToUnicodeEx((uint)rgKey[iKey].VK, rgKey[iKey].SC,
                        lpKeyState, sbBuffer, sbBuffer.Capacity, 0, hkl);
       if (rc == 1) {
         // That was indeed a base character for our dead key.
         // And we now have a composite character. Let's run
         // through one more time to get the actual base
         // character that made it all possible?
         char combchar = sbBuffer[0];
         sbBuffer = new StringBuilder(10);
         rc = ToUnicodeEx((uint)rgKey[iKey].VK, rgKey[iKey].SC,
                          lpKeyState, sbBuffer, sbBuffer.Capacity, 0, hkl);
         char basechar = sbBuffer[0];
         if (deadKey.DeadCharacter == combchar) {
           // Since the combined character is the same as the dead key,
           // we must clear out the keyboard buffer.
           ClearKeyboardBuffer((uint)KeysEx.VK_DECIMAL, rgKey[(uint)KeysEx.VK_DECIMAL].SC, hkl);
         }
         if ((((ss == ShiftState.LCtrl) || (ss == ShiftState.ShftLCtrl)) &&
             (char.IsControl(basechar))) ||
             (basechar.Equals(combchar))) {
           // ToUnicodeEx has an internal knowledge about those
           // VK_A ~ VK_Z keys to produce the control characters,
           // when the conversion rule is not provided in keyboard
           // layout files
           // Additionally, dead key state is lost for some of these
           // character combinations, for unknown reasons.
           // Therefore, if the base character and combining are equal,
           // and its a CTRL or CTRL+SHIFT state, and a control character
           // is returned, then we do not add this "dead key" (which
           // is not really a dead key).
           continue;
         }
         if (caps == 0 && (ss == ShiftState.Base || ss == ShiftState.Shft))
           deadKey.AddDeadKeyRow(rgKey[iKey].SC, caps, ss, combchar);
       } else if (rc > 1) {
         // Not a valid dead key combination, sorry! We just ignore it.
       } else if (rc < 0) {
         // It's another dead key, so we ignore it (other than to flush it from the state)
         ClearKeyboardBuffer((uint)KeysEx.VK_DECIMAL, rgKey[(uint)KeysEx.VK_DECIMAL].SC, hkl);
       }
     }
       }
     }
       }
       return deadKey;
 }
		public void SendKey(KeysEx keyCode)
		{
			PressKey(keyCode);
			ReleaseKey(keyCode);
		}
Beispiel #42
0
 private static void FillKeyState(KeysEx[] lpKeyState, ShiftState ss, bool fCapsLock)
 {
     lpKeyState[(int)KeysEx.VK_SHIFT] = (((ss & ShiftState.Shft) != 0) ? (KeysEx)0x80 : (KeysEx)0x00);
       lpKeyState[(int)KeysEx.VK_CONTROL] = (((ss & ShiftState.LCtrl) != 0) ? (KeysEx)0x80 : (KeysEx)0x00);
       lpKeyState[(int)KeysEx.VK_MENU] = (((ss & ShiftState.Menu) != 0) ? (KeysEx)0x80 : (KeysEx)0x00);
       if (Loader.RCtrlVk != KeysEx.None) {
     // The RCtrl key has been assigned, so let's include it
     lpKeyState[(int)Loader.RCtrlVk] = (((ss & ShiftState.RCtrl) != 0) ? (KeysEx)0x80 : (KeysEx)0x00);
       }
       lpKeyState[(int)KeysEx.VK_CAPITAL] = (fCapsLock ? (KeysEx)0x01 : (KeysEx)0x00);
 }
Beispiel #43
0
		public KeyStats(string name, KeysEx keyCode, bool useShift = false, string capName= null)
		{
			Name = name;
			KeyCode = keyCode;
			UseShift = useShift;
			ShiftName = string.Empty;
            CapName = string.Empty;
            if (!string.IsNullOrEmpty(Name))
			{
				ShiftName = Name.ToLowerInvariant();
                CapName = Name.ToUpperInvariant();
			}
		}
Beispiel #44
0
		/// <summary>
		/// Returns a value indicating whether a non-modifier key is currently pressed.
		/// </summary>
		/// <param name="key">The key to check. Key must not be a modifier bit mask.</param>
		/// <returns>True if the key is currently pressed; otherwise false.</returns>
		/// <exception cref="ArgumentException">Occurs if key is a modifier bit mask. </exception>
		static bool IsKeyPressed(KeysEx key)
		{
			if ((key & KeysEx.Modifiers) == KeysEx.Modifiers)
			{
				throw new ArgumentException("Key cannot contain any modifiers.", "key");
			}

			const int keyPressed = NativeMethods.KeyStateConstants.KEY_PRESSED;
			return (NativeMethods.GetKeyState((int)key) & keyPressed) == keyPressed;
		}
Beispiel #45
0
        /// <summary>
        /// Returns KeyCode portion of this instance. That is, the key stripped of modifiers.
        /// </summary>
        /// <param name="keys">The keys to remove modifier keys from.</param>
        static string UnmodifiedKey(KeysEx keys)
        {
            KeysEx keyCode = keys & KeysEx.KeyCode;

            switch (keyCode)
            {
                case KeysEx.Menu:
                case KeysEx.LMenu:
                case KeysEx.RMenu:
                case KeysEx.ShiftKey:
                case KeysEx.LShiftKey:
                case KeysEx.RShiftKey:
                case KeysEx.ControlKey:
                case KeysEx.LControlKey:
                case KeysEx.RControlKey:
                case KeysEx.LWin:
                case KeysEx.RWin:
                    return string.Empty;
            }

            switch (keyCode)
            {
                case KeysEx.D0:
                case KeysEx.D1:
                case KeysEx.D2:
                case KeysEx.D3:
                case KeysEx.D4:
                case KeysEx.D5:
                case KeysEx.D6:
                case KeysEx.D7:
                case KeysEx.D8:
                case KeysEx.D9:
                    return keyCode.ToString().Remove(0, 1);
            }

            if (keyCode.ToString().ToUpperInvariant().StartsWith("OEM"))
            {
                const uint convertToChar = 2;
                uint keyLiteral = NativeMethods.MapVirtualKey((uint)keyCode, convertToChar);
                return Convert.ToChar(keyLiteral).ToString(CultureInfo.InvariantCulture);
            }

            return keyCode.ToString();
        }
Beispiel #46
0
 private static extern int ToUnicodeEx(uint wVirtKey, uint wScanCode, KeysEx[] lpKeyState,
                                   StringBuilder pwszBuff, int cchBuff, uint wFlags,
                                   IntPtr dwhkl);
Beispiel #47
0
		/// <summary>
		/// Callback handler for keyboard lockdowns.
		/// </summary>
		static IntPtr LockdownHookCallBack(int nCode, IntPtr wParam, IntPtr lParam)
		{
			int keyStateParam = (int)wParam;
			KeysEx pressedKey = (KeysEx)Marshal.ReadInt32(lParam);

			switch (pressedKey)
			{
				case KeysEx.LControlKey:
				case KeysEx.RControlKey:
					pressedKey = KeysEx.Control;
					break;

				case KeysEx.RMenu:
				case KeysEx.LMenu:
					pressedKey = KeysEx.Alt;
					break;

				case KeysEx.LShiftKey:
				case KeysEx.RShiftKey:
					pressedKey = KeysEx.Shift;
					break;

				case KeysEx.LWin:
				case KeysEx.RWin:
					pressedKey = KeysEx.WinLogo;
					break;
			}

			KeyState keyState;
			if (keyStateParam == keyUp || keyStateParam == systemKeyUp)
			{
				keyState = KeyState.Up;
				lockedDownKeys ^= pressedKey;
			}
			else if (keyStateParam == keyDown || keyStateParam == systemKeyDown)
			{
				keyState = KeyState.Down;
				lockedDownKeys |= pressedKey;
			}
			else
			{
				throw new ArgumentOutOfRangeException("wParam", "Invalid key state detected.");
			}

			OnLockedDownKeyboardKeyPressed(lockedDownKeys, keyState);
			return new IntPtr(1);
		}
Beispiel #48
0
        /// <summary>
        /// Determines whether this enumeration contains the Shift modifier.
        /// </summary>
        /// <param name="keys">The keys to check for the Shift modifier.</param>
        /// <returns>True if this enumeration contains the Shift modifier; otherwise false.</returns>
        static bool IsShiftModified(KeysEx keys)
        {
            if ((keys & KeysEx.Shift) == KeysEx.Shift)
                return true;

            KeysEx keyCode = keys & KeysEx.KeyCode;
            switch (keyCode)
            {
                case KeysEx.ShiftKey:
                case KeysEx.LShiftKey:
                case KeysEx.RShiftKey:
                    return true;
            }

            return false;
        }
		public void ReleaseKey(KeysEx keyCode)
		{
			uint intReturn = 0;
			INPUT structInput;
			structInput = new INPUT();
			structInput.type = (uint)1;
			structInput.ki.wScan = 0;
			structInput.ki.time = 0;
			structInput.ki.dwFlags = 0;
			structInput.ki.dwExtraInfo = 0;

			// Key up the actual key-code
			structInput.ki.dwFlags = NativeWin32.KEYEVENTF_KEYUP;
			structInput.ki.wVk = (ushort)keyCode;// (ushort)NativeWin32.KeysEx.SNAPSHOT;//vk;
			intReturn = NativeWin32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput));
		}
Beispiel #50
0
 public VirtualKey(IntPtr hkl, KeysEx virtualKey)
 {
     this.m_sc = MapVirtualKeyEx((uint)virtualKey, 0, hkl);
       this.m_hkl = hkl;
       this.m_vk = (uint)virtualKey;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyboardLockDownKeyPressedEventArgs"/> class.
 /// </summary>
 /// <param name="keys">The keys that were pressed.</param>
 /// <param name="state">The state of the pressed keys.</param>
 /// <remarks></remarks>
 public KeyboardLockDownKeyPressedEventArgs(KeysEx keys, KeyState state)
 {
     Keys = keys;
     State = state;
 }