Exemple #1
0
        private void ProcessKeyWord(KeyWord keyword)
        {
            IntPtr wnd = GetForegroundWindow();

            if (wnd == m_Form.Handle)
            {
                MessageBox.Show("Please set input area", m_title);
                return;
            }
            if (keyword.AttachedText == null)
            {
                return;
            }
            if (m_playClickSound)
            {
                m_playClickCount++; // play "click" on each mouse click
            }
            if (keyword.IsShellCommand)
            {
                ProcessCommand(keyword.AttachedText);
            }
            else
            {
                m_keybd.ProcessKeyWord(keyword); // process string corresponding to selected key
                SetCurrentCapsShiftCtrlAlt();
            }
        }
Exemple #2
0
 private int GetSameItemKeyWordIndex(KeyWord kw)
 {
     for (int j = 0; j < m_KeyWords.Length; j++)
     {
         int i = m_KeyWords.Length - j - 1;
         if (m_KeyWords[i].LowerText.Equals(kw.LowerText, StringComparison.InvariantCulture) &&
             m_KeyWords[i].AttachedText.Equals(kw.AttachedText, StringComparison.InvariantCulture))
         {
             return(i);
         }
     }
     return(-1);
 }
Exemple #3
0
 private void AddKeyWord(string[] keyWord, Font useFont)
 {
     if (keyWord.Length > 0)
     {
         KeyWord kw      = new KeyWord(keyWord, m_AllItems.Length, useFont);
         int     nspaces = kw.Start - m_AllItems.Length;
         while (nspaces > 0)
         {
             m_AllItems += " ";
             nspaces--;
         }
         kw.IndexSameItem = GetSameItemKeyWordIndex(kw);
         // add KeyWord kw to m_KeyWords
         Array.Resize(ref m_KeyWords, m_KeyWords.Length + 1);
         m_KeyWords[m_KeyWords.Length - 1] = kw;
         m_AllItems += " " + kw.Text + " ";
     }
 }
 public void ProcessKeysString(string str, KeyWord keyword)
 {
     Array.Clear(inputs, 0, inputs.Length);
     inputs = Array.Empty <INPUT>();
     while (str.Length > 0)
     {
         int itemLength = 0;
         if (str.StartsWith("{", StringComparison.InvariantCultureIgnoreCase) && (itemLength = str.IndexOf('}') + 1) > 0)
         {
             if (ChangeCase(str))
             {
             }
             else if (str.StartsWith("{BACKSPACE}", StringComparison.InvariantCultureIgnoreCase))
             {
                 SimulateKeybdKeyClick(VK_BACK);
             }
             else if (str.StartsWith("{ALT}", StringComparison.InvariantCultureIgnoreCase))
             {
                 m_altPressed = !m_altPressed;
                 if (m_altPressed)
                 {
                     SimulateKeybdKeyDown(VK_MENU);
                 }
                 else
                 {
                     SimulateKeybdKeyUp(VK_MENU);
                 }
             }
             else if (str.StartsWith("{PRTSC}", StringComparison.InvariantCultureIgnoreCase))
             {
                 SimulateKeybdKeyClick(VK_SNAPSHOT);
                 if (m_altPressed)
                 {
                     m_altPressed = false;
                     SimulateKeybdKeyUp(VK_MENU);
                 }
             }
             else if (str.StartsWith("{DEL}", StringComparison.InvariantCultureIgnoreCase))
             {
                 SimulateKeybdKeyClick(VK_DELETE);
             }
             else if (str.StartsWith("{CTRL}", StringComparison.InvariantCultureIgnoreCase))
             {
                 m_ctrlPressed = !m_ctrlPressed;
                 if (m_ctrlPressed)
                 {
                     SimulateKeybdKeyDown(VK_CONTROL);
                 }
                 else
                 {
                     SimulateKeybdKeyUp(VK_CONTROL);
                 }
             }
             else if (str.StartsWith("{SHIFT}", StringComparison.InvariantCultureIgnoreCase))
             {
                 m_shiftPressed = !m_shiftPressed;
                 if (m_shiftPressed)
                 {
                     SimulateKeybdKeyDown(VK_SHIFT);
                 }
                 else
                 {
                     SimulateKeybdKeyUp(VK_SHIFT);
                 }
                 CaseChanged = true;
             }
             else if (str.StartsWith("{CAPSLOCK}", StringComparison.InvariantCultureIgnoreCase))
             {
                 m_capsPressed = !m_capsPressed;
                 SimulateKeybdKeyClick(VK_CAPITAL);
                 CaseChanged = true;
             }
             else if (str.StartsWith("{SPACE}", StringComparison.InvariantCultureIgnoreCase))
             {
                 SimulateKeybdKeyClick(VK_SPACE);
             }
             else if (str.StartsWith("{ESCAPE}", StringComparison.InvariantCultureIgnoreCase))
             {
                 SimulateKeybdKeyClick(VK_ESCAPE);
             }
             else if (str.StartsWith("{ENTER}", StringComparison.InvariantCultureIgnoreCase))
             {
                 SimulateKeybdKeyClick(VK_RETURN);
                 SendKeybdInput(); // flush current input
                 ResetShiftCtrlAltKeysStates();
             }
             else if (str.StartsWith("{TAB}", StringComparison.InvariantCultureIgnoreCase))
             {
                 SimulateKeybdKeyClick(VK_TAB);
                 SendKeybdInput(); // needed for alt+tab in win7
                 Thread.Sleep(10); // needed for alt+tab in win7
                 ResetShiftCtrlAltKeysStates();
             }
             else if (str.StartsWith("{F", StringComparison.InvariantCultureIgnoreCase))
             {
                 if (int.TryParse(str.Substring(2, itemLength - 3), out int fv) && fv >= 1 && fv <= 24)
                 {
                     ushort fk = (ushort)(VK_F1 - 1 + fv);
                     SimulateKeybdKeyClick(fk);
                 }
             }
             else if (str.StartsWith("{VK_0X", StringComparison.InvariantCultureIgnoreCase))
             {
                 // https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
                 if (int.TryParse(str.Substring(6, itemLength - 7), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int vk) &&
                     vk >= 1 && vk <= 254)   // && vk != 0x07 && vk != 0x16 && vk != 0x1a && (vk < 0x3a || vk > 0x40) && (vk < 0x88 || vk > 0x8f)
                 {
                     SimulateKeybdKeyClick((ushort)(vk));
                 }
             }
             else if (str.StartsWith("{VK_UP_0X", StringComparison.InvariantCultureIgnoreCase))
             {
                 if (int.TryParse(str.Substring(9, itemLength - 10), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int vk) &&
                     vk >= 1 && vk <= 254)   // && vk != 0x07 && vk != 0x16 && vk != 0x1a && (vk < 0x3a || vk > 0x40) && (vk < 0x88 || vk > 0x8f)
                 {
                     SimulateKeybdKeyUp((ushort)(vk));
                 }
             }
             else if (str.StartsWith("{VK_DOWN_0X", StringComparison.InvariantCultureIgnoreCase))
             {
                 if (int.TryParse(str.Substring(9, itemLength - 10), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int vk) &&
                     vk >= 1 && vk <= 254)   // && vk != 0x07 && vk != 0x16 && vk != 0x1a && (vk < 0x3a || vk > 0x40) && (vk < 0x88 || vk > 0x8f)
                 {
                     SimulateKeybdKeyDown((ushort)(vk));
                 }
             }
             else
             {
                 itemLength = 0;
             }
         }
         if (itemLength == 0)
         {
             char firstChar = str[0];
             itemLength = 1;
             if (firstChar >= 'a' && firstChar <= 'z' && CtrlOrAltPressed())
             {
                 SimulateKeybdKeyClick((ushort)Char.ToUpperInvariant(firstChar));
             }
             else if (firstChar >= 'A' && firstChar <= 'Z' && CtrlOrAltPressed())
             {
                 SimulateKeybdKeyClick((ushort)firstChar);
             }
             else if (keyword.CanBeUsedWithShift)
             {
                 if (m_shiftPressed != m_capsPressed)
                 {
                     SimulateKeybdString(keyword.UpperText);
                 }
                 else
                 {
                     SimulateKeybdString(keyword.LowerText);
                 }
                 itemLength = str.Length;
             }
             else
             {
                 SimulateKeybdString(firstChar.ToString());
             }
             SendKeybdInput();
             ResetShiftCtrlAltKeysStates();
         }
         str = str.Substring(itemLength, str.Length - itemLength);
     }
     SendKeybdInput();
 }
        public void ProcessKeyWord(KeyWord keyword)
        {
            string str = keyword.AttachedText;

            ProcessKeysString(str, keyword);
        }