Beispiel #1
0
        public frmMain()
        {
            InitializeComponent();

            AppRunning = true;

            //Pull in some settings from an ini file:
            ini = new IniFile(Application.StartupPath + "\\AutoItX.ini");
            bool success;
            int SendKeyDelay = myUtils.StringToInt(ini.IniReadValue("AUTOITXSETTINGS", "SendKeyDelay"), out success);
            if (!success) SendKeyDelay = 5;     //load default value
            int WinWaitDelay = myUtils.StringToInt(ini.IniReadValue("AUTOITXSETTINGS", "WinWaitDelay"), out success);
            if (!success) WinWaitDelay = 250;

            ///Alters the the length of the brief pause in between sent keystrokes.
            ///Time in milliseconds to pause (default=5). Sometimes a value of 0 does not work; use 1 instead.
            AutoItX.AU3_AutoItSetOption("SendKeyDelay", SendKeyDelay);

            ///Alters the method that is used to match window titles during search operations.
            ///1 = Match the title from the start (default)
            ///2 = Match any substring in the title
            ///3 = Exact title match
            ///4 = Advanced mode, see Window Titles & Text (Advanced)
            AutoItX.AU3_AutoItSetOption("WinTitleMatchMode", 2);

            ///WinWaitDelay Alters how long a script should briefly pause after a successful window-related operation.
            ///Time in milliseconds to pause (default=250).
            AutoItX.AU3_AutoItSetOption("WinWaitDelay", WinWaitDelay);

            ///WinSearchChildren Allows the window search routines to search child windows as well as top-level windows.
            ///0 = Only search top-level windows (default)
            ///1 = Search top-level and child windows
            AutoItX.AU3_AutoItSetOption("WinSearchChildren", 0);

            //When using the COM library (rater than dllimport):
            //AutoItX3Lib.AutoItX3Class Au3Class = new AutoItX3Lib.AutoItX3Class();
            //Au3Class.

            //Simple keyboard hook set up with a callback to eventKeyPress on keyboard events:
            myKeyboardMouseHook = new KeyboardMouseHook(eventKeyPress);

            //Simple hotkey handler to allow registering hotkeys each with their own callbacks
            //(also hotkeys pressed are CONSUMED, meaning windows will not pass them down to other applications)
            //Or in other words, if this application registers a given hotkey, that hotkey will ONLY be seen by this
            //application.
            //Very important: be sure to override WndProc(ref Message m) and add a function call to myHotkeyHandler.WndProc(ref m)
            myHotkeyHandler = new HotkeyHandler(this.Handle);

            myHotkeyHandler.HotkeySet(HotkeyHandler.KeyModifiers.Control | HotkeyHandler.KeyModifiers.Alt, Keys.A, eventHotkeyCtrlAltA);
            myHotkeyHandler.HotkeySet(HotkeyHandler.KeyModifiers.None, Keys.B, eventHotkeyB);

            myHotkeyHandler.HotkeySet(HotkeyHandler.KeyModifiers.Control, Keys.B, AutoItXScriptRun);

            //Set up a tray icon with a context menu
            SetupTrayIcon();

            //Comment this out to cause the form to start hidden (only show the tray icon):
            this.Show();
        }
Beispiel #2
0
        void eventKeyPress(KeyboardMouseHook.AllKeys KeyCode, KeyboardMouseHook.ModifierEvent e, Point pt)
        {
            /*
            //Some useful information can also be gotten from the windows forms Control interface:
            //Control.MousePosition
            //Control.MouseButtons
             */

            string Mods = "";
            //These can be used to retrive the static state of the modifier keys:
            if (((int)myKeyboardMouseHook.Modifiers & (int)KeyboardMouseHook.KeyModifiers.LCtrl) != 0) Mods += "LCtrl ";
            if (((int)myKeyboardMouseHook.Modifiers & (int)KeyboardMouseHook.KeyModifiers.LAlt) != 0) Mods += "LAlt ";
            if (((int)myKeyboardMouseHook.Modifiers & (int)KeyboardMouseHook.KeyModifiers.LShift) != 0) Mods += "LShift ";
            if (((int)myKeyboardMouseHook.Modifiers & (int)KeyboardMouseHook.KeyModifiers.LWindows) != 0) Mods += "LWin ";

            if (((int)myKeyboardMouseHook.Modifiers & (int)KeyboardMouseHook.KeyModifiers.RCtrl) != 0) Mods += "RCtrl ";
            if (((int)myKeyboardMouseHook.Modifiers & (int)KeyboardMouseHook.KeyModifiers.RAlt) != 0) Mods += "RAlt ";
            if (((int)myKeyboardMouseHook.Modifiers & (int)KeyboardMouseHook.KeyModifiers.RShift) != 0) Mods += "RShift ";
            if (((int)myKeyboardMouseHook.Modifiers & (int)KeyboardMouseHook.KeyModifiers.RWindows) != 0) Mods += "RWin ";

            if (KeyCode == KeyboardMouseHook.AllKeys.None)
            {
                //First handle MOUSE events:

                Debug.WriteLine("Mouse event: " + e.ToString() + " " + pt.ToString());
            }
            else if (e != KeyboardMouseHook.ModifierEvent.None)
            {
                //To retrieve Modifier keydown and keyup Events, check the ModifierEvent argument e:
                if (e.ToString().Contains("Down"))
                {
                    Debug.WriteLine("Key pressed: 0x" + myUtils.Dec2Hex((int)KeyCode) + " " + KeyCode.ToString() + " Down");
                }
                else
                {
                    Debug.WriteLine("Key pressed: 0x" + myUtils.Dec2Hex((int)KeyCode) + " " + KeyCode.ToString() + " Up");
                }
            }
            else
            {
                string Character = myKeyboardMouseHook.KeyCodeToString(KeyCode);

                //All non-modifier keys will appear here:
                Debug.WriteLine("Key pressed: 0x" + myUtils.Dec2Hex((int)KeyCode) + " " + Mods + KeyCode.ToString());
                lblKeys.Text += Character;
            }
        }