예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            SetTarget();
            //here we resolve the 'a' to be a keycode of 4 by using the keycode list
            var k = KeyboardUtils.GetKeyKeyCode("a");

            if (k > 0)
            {
                Send(0, 0, k, 0, 0, 0, 0, 0);
                //keep the key pressed for this many ms.  If you hold it down for a long time, it will activate the OS key repeat function
                //we'll use a timer here to release the key as the repeat function won't activate when using System.Threading.Thread.Sleep().
                tmrRelease.Start();
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            SetTarget();
            //here we resolve the 'a' to be a keycode of 4 by using the keycode list
            var k = KeyboardUtils.GetKeyKeyCode("a");

            if (k > 0)
            {
                Send(0, 0, k, 0, 0, 0, 0, 0);
                //keep the key pressed for this many ms.  If you hold it down for a long time, it will activate the OS key repeat function
                System.Threading.Thread.Sleep(50);
                //we'll release the 'a' key by no longer including it in the pressed key list
                KeyReset();
            }
        }
예제 #3
0
        private void button6_Click(object sender, EventArgs e)
        {
            SetTarget();
            var k1 = KeyboardUtils.GetKeyKeyCode("a");
            var k2 = KeyboardUtils.GetKeyKeyCode("b");

            if ((k1 > 0) && (k2 > 0))
            {
                //you can press up to six keys (not including modifiers) simultaneously.
                Send(0, 0, k1, k2, 0, 0, 0, 0);
                //keep the key pressed for this many ms.  If you hold it down for a long time, it will activate the OS key repeat function
                System.Threading.Thread.Sleep(50);
                //we'll release the 'a' and 'b' key by no longer including it in the pressed key list
                KeyReset();
            }
        }
예제 #4
0
        private void SendText(string text, int Down, int Interkey)
        {
            SetTarget();
            //this example sends a simple 'Hello'.  If you want to use other modifers or keys like 'SPACEBAR' or 'TAB' you'll need to tweak this code.
            //we will put each character in the key0 slot, wait a bit, clear the slot, wait a bit and then do the next letter
            int  m;
            byte m1;
            byte k1;

            //iterate through the text.  We'll send one character at a time
            for (var i = 0; i < text.Length; i++)
            {
                var t = text[i];
                //check for uppercase letters
                if (t == char.ToUpper(t))
                {
                    m = KeyboardUtils.GetModifierKeyCode("[LSHIFT]");
                }
                else
                {
                    //no modifier needed
                    m = -1;
                }
                //the modifier is represented by bit positions in a single byte
                //in this example we are allowing only one modifier to be pressed
                //but you could have something like a LALT-LSHIFT-A sequence which means
                //that you would need to set the bit for LALT, then OR that with LSHIFT to give a value of 6
                //in this example, we are only handling [LSHIFT].
                //calc the modifier
                switch (m)
                {
                case 0: m1 = 1; break;

                case 1: m1 = 2; break;

                case 2: m1 = 4; break;

                case 3: m1 = 8; break;

                case 4: m1 = 16; break;

                case 5: m1 = 32; break;

                case 6: m1 = 64; break;

                case 7: m1 = 128; break;

                default: m1 = 0; break;
                }
                //the keycode is the same whether it is capitalized or not
                k1 = KeyboardUtils.GetKeyKeyCode(char.ToLower(t).ToString());
                if (k1 > 0)
                {
                    //pressing the key down
                    Send(m1, 0, k1, 0, 0, 0, 0, 0);
                    //keep the key pressed for this many ms.
                    System.Threading.Thread.Sleep(Down);
                    //release the key
                    KeyReset();
                    //wait before sending the next key
                    System.Threading.Thread.Sleep(Interkey);
                }
            }
        }