Esempio n. 1
0
        public void _listener_OnKeyPressed(Object sender, KeyPressedArgs e)
        {
            /* if (Keyboard.GetKeyStates(Key.LeftCtrl) == KeyStates.Down && Keyboard.GetKeyStates(Key.LeftShift) == KeyStates.Down
             *   && e.KeyPressed == Key.R)*/
            //if(e.KeyPressed == Key.PageUp&& e.KeyPressed== Key.PageDown)
            if ((Keyboard.GetKeyStates(Key.PageUp) == KeyStates.Down && e.KeyPressed == Key.PageDown) || (Keyboard.GetKeyStates(Key.PageDown) == KeyStates.Down && e.KeyPressed == Key.PageUp))
            {
                if (recording)
                {
                    System.Windows.Forms.MessageBox.Show("Recording halted");
                    recording = false;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Recording");
                    recording = true;
                }
            }

            int posX = System.Windows.Forms.Cursor.Position.X,
                posY = System.Windows.Forms.Cursor.Position.Y;

            switch (e.KeyPressed)
            {
            case Key.Left:
                System.Windows.Forms.Cursor.Position = new System.Drawing.Point(posX - 10, posY);
                break;

            case Key.Right:
                System.Windows.Forms.Cursor.Position = new System.Drawing.Point(posX + 10, posY);
                break;

            case Key.Up:
                System.Windows.Forms.Cursor.Position = new System.Drawing.Point(posX, posY - 10);
                break;

            case Key.Down:
                System.Windows.Forms.Cursor.Position = new System.Drawing.Point(posX, posY + 10);
                break;

            default:
                break;
            }
            if (recording)
            {
                using (Stream str = new FileStream(pathName, FileMode.Append, FileAccess.Write))
                {
                    using (StreamWriter writer = new StreamWriter(str))
                    {
                        if (!(e.KeyPressed == Key.LeftCtrl || Keyboard.GetKeyStates(Key.LeftShift) == KeyStates.Down || Keyboard.GetKeyStates(Key.RightShift) == KeyStates.Down))
                        {
                            writer.Write(e.KeyPressed.ToString().ToLower() + " ");
                        }
                        else if (Keyboard.GetKeyStates(Key.LeftShift) == KeyStates.Down && e.KeyPressed != Key.HanjaMode)
                        {
                            if (e.KeyPressed != Key.RightShift || e.KeyPressed != Key.LeftShift)
                            {
                                writer.Write(e.KeyPressed.ToString().ToUpper() + " ");//Will caps the key that you enter into the text file
                            }
                        }
                    }
                }
            }
        }