Exemple #1
0
 public Actions(string type, System.Windows.Forms.Keys keys, System.Windows.Forms.Keys modifier, float timer) {
     // TODO: Complete member initialization
     this.type = type;
     this.keys = keys;
     this.timer = timer;
     this.keyModifier = modifier;
 }
 internal KeyBoardHookEventArgs(System.IntPtr wParam, System.IntPtr lParam)
 {
     int num = (int) wParam;
     if (!System.Enum.IsDefined(typeof(System.Windows.Forms.Keys), (int) num))
     {
         this.virtKey = System.Windows.Forms.Keys.None;
     }
     else
     {
         this.virtKey = (System.Windows.Forms.Keys) num;
     }
     this.keyFlags = (int) lParam;
 }
        public KeyboardKeyDownUpSource(
            Enums.Keys triggerKey,
            IObservable<Timestamped<PointAndKeyValue?>> pointAndKeyValueSource)
        {
            this.triggerKey = (System.Windows.Forms.Keys)triggerKey; //Cast to the Windows.Forms.Keys enum
            this.pointAndKeyValueSource = pointAndKeyValueSource;

            keyboardHookListener = new KeyboardHookListener(new GlobalHooker())
            {
                Enabled = true
            };

            /*
             * Keys: http://msdn.microsoft.com/en-GB/library/system.windows.forms.keys.aspx
             * KeyDown: happens when the person presses a key (when the keyboard first detects a finger on a key, this happens when the key is pressed down).
             * KeyPress: happens when a key is pressed and then released.
             * KeyUp: happens when the key is released
             */
        }
        protected override bool HandleKeyDown(KeyEventArgs args)
        {
            _lastPressedKey = Keys.None;

            if (args.Modifiers == Keys.None)
            {
                Keys Key = args.KeyCode;

                _lastPressedKey = args.KeyCode;

                string newFilterStr = null;

                bool f = false;

                if (Key == System.Windows.Forms.Keys.Delete)
                {
                    newFilterStr = null;

                    f = true;
                }
                else if (Key == System.Windows.Forms.Keys.Back)
                {
                    if (!string.IsNullOrEmpty(_filterString))
                        newFilterStr = FilterString.Remove(_filterString.Length - 1, 1);
                    else
                        newFilterStr = null;

                    f = true;
                }

                if (f)
                {
                    this.FilterString = newFilterStr;

                    return true;
                }
            }

            return base.HandleKeyDown(args);
        }
 private static IntPtr KeyboardHookProc(int code, int wParam, ref SSWindowsFunctions.KeyboardHookStruct lParam)
 {
     if (code >= 0 && (wParam == SSWindowsFunctions.WM_KEYDOWN || wParam == SSWindowsFunctions.WM_SYSKEYDOWN))
     {
         var key = (System.Windows.Forms.Keys)Enum.Parse(typeof (System.Windows.Forms.Keys), lParam.vkCode.ToString());
         if (key == Keys.PrintScreen)
         {
             System.Diagnostics.Debug.WriteLine($"Combination: {key}");
             ((SSBaseHookSystem)GetHookSystem()).InteractionManager.GetCommand<SSKeyboardProvider>().Publish(new SSKeyboardPayload() { Value = eScreenshotType.Screen });
         }
         else if (LastKey == Keys.LControlKey && key == Keys.NumPad1)
         {
             System.Diagnostics.Debug.WriteLine($"Combination: {LastKey}+{key}");
             ((SSBaseHookSystem)GetHookSystem()).InteractionManager.GetCommand<SSKeyboardProvider>().Publish(new SSKeyboardPayload() {Value = eScreenshotType.SelectedArea});
         }
         else if (LastKey == Keys.LControlKey && key == Keys.NumPad2)
         {
             System.Diagnostics.Debug.WriteLine($"Combination: {LastKey}+{key}");
             ((SSBaseHookSystem)GetHookSystem()).InteractionManager.GetCommand<SSKeyboardProvider>().Publish(new SSKeyboardPayload() { Value = eScreenshotType.SelectedWindow });
         }
         LastKey = key;
     }
     return SSWindowsFunctions.CallNextHookEx( ((SSBaseHookSystem)GetHookSystem()).GetHookPtr() , code, (int)wParam, SSWindowsFunctions.StructToPtr(lParam));
 }
 private static void AddKeys(WinFormsKeys fromKey, Keys toKey)
 {
     if (!mapKeys.ContainsKey(fromKey))
     {
         mapKeys.Add(fromKey, toKey);
     }
 }
 internal KeyPressedEventArgs(HotKeyboardHook.ModifierKeys modifier, WF.Keys key)
 {
     _modifier = modifier;
     _key = key;
 }
        private bool Instance_ProcessCmdKeyCallback(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            //Add our shortcut

            if (keyData == (Keys.Alt | Keys.A))
            {
                do_parameters(this, null);
                return(true);
            }
            return(false);
        }
Exemple #9
0
 public static int GetKeyCode(string code)
 {
     System.Windows.Forms.Keys key = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), code, true);
     return((int)key);
 }
Exemple #10
0
        private bool Instance_ProcessCmdKeyCallback(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            //Add our shortcut

            if (keyData == (Keys.Alt | Keys.D))
            {
                GetDescription();
                UpdateTitleBar();
            }
            return(true);
        }
Exemple #11
0
        public virtual void AddIgnoredKey(System.Windows.Forms.Keys shortcutkey)
        {
            int key = (int)shortcutkey;

            this._ignoredKeys.Add(key, key);
        }
 /// <summary>
 /// Tests if Windows key is an input key by calling ATF IsInputKey with converted argument</summary>
 /// <param name="keyData">Windows key data</param>
 /// <returns>True iff key is an input key</returns>
 protected override bool IsInputKey(WfKeys keyData) { return IsInputKey(KeysInterop.ToAtf(keyData)); }
Exemple #13
0
 /// <summary>
 /// Obs³uga wciœniêcia klawisza klawiatury w przypadku nie wykrycia przez Form
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Game_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
 {
     key_pressed = e.KeyCode;
     move = true;
 }
Exemple #14
0
        static public SharpDX.DirectInput.Key KeysToSharpKey(System.Windows.Forms.Keys ky) // Keys -> Sharp DX
        {
            Key k = sharptokeys.FirstOrDefault(x => x.Value == ky).Key;                    // if not found, returns enum 0, or Key.Unknown!

            return(k);
        }
        public void PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
            // Ignore shortcut keys when Config screen is visible
            // Ignore repeated keys
            if (this.previousKey == e.KeyCode) {
                this.previousKey = 0;
                //Console.WriteLine("PreviousKey:" + e.KeyCode.ToString());
            } else {
                //Console.WriteLine("Key:" + e.KeyCode.ToString());
                if (this.config.ActiveControl != null) Console.WriteLine(this.config.ActiveControl.Name);
                else Console.WriteLine("null");
                if (this.config.Visible && this.config.WindowState != FormWindowState.Minimized) {
                    switch (e.KeyCode) {
                        case Keys.Escape:
                            if (this.config.WindowState == FormWindowState.Minimized) {
                                this.config.WindowState = FormWindowState.Normal;
                            } else {
                                if (this.action == Actions.Config) {
                                    this.config.Config_FormClosing(this, null);
                                    //this.OnExit();
                                } else {
                                    this.configHidden = true;
                                    this.config.Hide();
                                }
                            }
                        break;
                        #if (DEBUG)
                        case Keys.F12:
                            this.config.saveDebug();   
                            MessageBox.Show(this.config.jsonAllPersistant());
                            /*string log = "HTML saved";
                            foreach(string s in this.debugLog) {
                                log += s + Environment.NewLine;
                            }
                            MessageBox.Show(log, "Debug log:");*/
                        break;
                        #endif
                        case Keys.S:
                            if (this.config != Form.ActiveForm) {
                                this.config.Activate();
                            }
                        break;
                    }
                } else {
		            Keys KeyCode = e.KeyCode;
		            // fix German keyboard codes for [ ]
		            if (e.Alt && e.Control) {
			            switch (e.KeyCode) {
				            case Keys.D8: 
                                KeyCode = Keys.OemOpenBrackets;
				            break;
				            case Keys.D9:
					            KeyCode = Keys.OemCloseBrackets;
				            break;
			            }
		            }
                    if (e.Control && KeyCode >= Keys.D0 && KeyCode <= Keys.D5) {
                        // Control + 0 ... 5 set Rating
                        this.stopTimers();
                        int rating = KeyCode - Keys.D0;

                        for (int i = 0; i < this.monitors.Length; i++) {
                            if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                this.monitors[i].rateImage(rating);
                            }
                        }
                        this.fileNodes.resetFilter();
                        this.startTimers();
                    } else switch (KeyCode) {
                        case Keys.Escape:
                            if (!this.configHidden) {
                                this.OnExit();
                            }
                            this.configHidden = false;
                        break;
                        case Keys.A:
                            Utils.RunTaskScheduler(@"OpenUrl", "http://www.abscreensavers.com");                    
                        break;
                        case Keys.B:
                            Utils.RunTaskScheduler(@"OpenUrl", "http://www.abscreensavers.com/random-photo-screensaver/version-information/");
                            //this.monitors[i].showInfoOnMonitor("Opened in Explorer Window", false, true);
                            //Process.Start("http://www.abscreensavers.com");
                        break;
                        case Keys.C:
                            string c;
                            if (!e.Control && this.clipboardReady ) c = Clipboard.GetText();
                            else c = "";
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    if (this.monitors[i].imagePath() != null) {
                                        c += this.monitors[i].imagePath() + Environment.NewLine;
                                        if (e.Control) {
                                            c += this.monitors[i].quickMetadata.getAsString() + Environment.NewLine + Environment.NewLine;
                                            this.monitors[i].showInfoOnMonitor("Metadata copied to clipboard");
                                        } else this.monitors[i].showInfoOnMonitor("Image path added to clipboard");
                                    }
                                }
                            }
                            if (c != "") {
                                Clipboard.SetText(c);
                                this.clipboardReady = true;
                            }
                        break;
                        case Keys.E:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    if (this.monitors[i].imagePath() != null) {
                                        if (e.Control) {
                                            if (!File.Exists(Convert.ToString(this.config.getPersistant("externalEditor")))) {
                                                this.monitors[i].showInfoOnMonitor("External editor: '" + this.config.getPersistant("externalEditor") + "' not found.", true, true);
                                            } else {
                                                if (Utils.RunTaskScheduler(@"OpenInEditor" + Convert.ToString(i), Convert.ToString(this.config.getPersistant("externalEditor")), "\"" + this.monitors[i].imagePath() + "\"")) {
                                                    this.monitors[i].showInfoOnMonitor("Opened in external editor", false, true);
                                                }
                                            }
                                        } else {
                                            if (Utils.RunTaskScheduler(@"OpenInExplorer" + Convert.ToString(i), "explorer.exe", "/e,/select,\"" + this.monitors[i].imagePath() + "\"")) { 
                                                this.monitors[i].showInfoOnMonitor("Opened in Explorer Window", false, true);
                                            }
                                        }
                                    }
                                }
                            }
                            if (Convert.ToBoolean(this.config.getPersistantBool("closeAfterImageLocate"))) this.OnExit();
                        break;
                        case Keys.F:
                        case Keys.NumPad7:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.config.setPersistant("showFilenameM" + (i + 1), Convert.ToString(this.monitors[i].InvokeScript("toggle", new string[] { "#filename" })));
                                }
                            }
                        break;
                        case Keys.H:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    if (this.monitors[i].imagePath() != null) {
                                        FileAttributes attributes = File.GetAttributes(this.monitors[i].imagePath());
                                        if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) {
                                            attributes = attributes & ~FileAttributes.Hidden;
                                            this.monitors[i].showInfoOnMonitor("Showing image<br/>(Hidden file attribute cleared)", false, true);
                                        } else {
                                            attributes = attributes | FileAttributes.Hidden;
                                            this.monitors[i].showInfoOnMonitor("Hiding image<br/>(Hidden file attribute set and removed from DB)", false, true);
                                            this.fileNodes.deleteFromDB(this.monitors[i].imagePath());
                                        }
                                        File.SetAttributes(this.monitors[i].imagePath(), attributes);
                                    }
                                }
                            }
                            if (Convert.ToBoolean(this.config.getPersistantBool("closeAfterImageLocate"))) this.OnExit();
                        break;
                        case Keys.I:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].browser.Document.InvokeScript("identify");
                                }
                            }
                        break;
                        case Keys.M:
                        case Keys.N:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.config.setPersistant("showQuickMetadataM" + (i + 1), Convert.ToString(this.monitors[i].InvokeScript("toggle", new string[] { "#quickMetadata" })));
                                }
                            }
                        break;
                        case Keys.P:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    if (!this.config.syncMonitors() || i == 0) {
                                        this.monitors[i].paused = !this.monitors[i].paused;
                                        this.monitors[i].timer.Enabled = !this.monitors[i].paused;
                                    } else {
                                        this.monitors[i].paused = this.monitors[0].paused;
                                        this.monitors[i].timer.Enabled = !this.monitors[0].paused;
                                    }
                                    if (this.monitors[i].timer.Enabled) this.monitors[i].showInfoOnMonitor("|>");
                                    else this.monitors[i].showInfoOnMonitor("||");
                                }
                            }
                        break;
                        case Keys.R: case Keys.NumPad1:
                            if (this.config.changeOrder() == Config.Order.Random) {
                                this.showInfoOnMonitors("Randomising");
                            } else {
                                int monitor = this.currentMonitor;
                                if (this.currentMonitor == CM_ALL) monitor = 0;
                                if (this.monitors[monitor].currentImage != null) {
                                    this.fileNodes.currentSequentialSeedId = Convert.ToInt32(this.monitors[monitor].currentImage["id"]);
                                }
                                this.showInfoOnMonitors("Sequential");
                            };
                        break;
                        case Keys.S:
                            // Don't hide config screen if application is in Config mode
                            if (this.action != Actions.Config) {
                                if (this.config.Visible && this.config.WindowState != FormWindowState.Minimized)  this.config.Hide();
                                else {
                                    this.config.Activate();
                                    this.config.Show();
                                    this.config.WindowState = FormWindowState.Normal;
                                }
                            }
                        break;
                        case Keys.T: case Keys.NumPad5:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    string display = "true";
                                    string clockType = "current";
                                    switch(Convert.ToString(this.config.getPersistant("clockM" + (i + 1)))) {
                                        case "none":
                                            this.config.setPersistant("currentClockM" + (i + 1), "checked");
                                            clockType = "current";
                                        break;
                                        case "current":
                                            this.config.setPersistant("elapsedClockM" + (i + 1), "checked");
                                            clockType = "elapsed";
                                        break;
                                        case "elapsed":
                                            this.config.setPersistant("noClockM" + (i + 1), "checked");
                                            clockType = "none";
                                            display = "false";
                                        break;
                                    }
                                    this.config.setPersistant("clockM" + (i + 1), clockType);
                                    this.monitors[i].InvokeScript("setClockType", new string[] { clockType  });
                                    this.monitors[i].InvokeScript("toggle", new string[] { "#clock", display });
                                    this.monitors[i].InvokeScript("setClockFormat", new string[] { this.config.getPersistantString("clockFormatM" + (i + 1)) });
                                }
                            }
                        break;
                        case Keys.U:
                            string updateFilename = this.config.updateFilename();
                            if (updateFilename == null) {
                                this.showUpdateStatus = true;
                                this.showInfoOnMonitors("Checking for updates.", true, true);
                                this.config.timerCheckUpdates_Tick(this, null);
                            } else {
                                if (e.Control) {
                                    string update = this.config.getUpdateVersion();
                                    if (update != null) {
                                        this.config.setPersistant("ignoreVersion", update);
                                        this.config.setPersistant("ignoreUpdate", Convert.ToString(true));
                                        this.hideUpdateInfo();
                                        this.showInfoOnMonitors("Update " + update + " will be ignored.", true, true);
                                    }
                                } else {
                                    switch (this.config.isUpdateNewer()) { 
                                        case true:
                                            this.showInfoOnMonitors("Activating update", true, true);
                                            if (File.Exists(updateFilename) && Utils.VerifyMD5(updateFilename, this.config.updateFileMD5())) {
                                                // Keep call to explorer.exe otherwise update won't start!
                                                Utils.RunTaskScheduler(@"Run", "explorer.exe", updateFilename);
                                            } else {
                                                Utils.RunTaskScheduler(@"Run", "explorer.exe", this.config.updateDownloadUrl());
                                            }
                                            this.OnExit();
                                        break;
                                        case false:
                                            this.showAllUpToDate();
                                        break;
                                        case null:
                                        break;
                                    }
                                }
                            }
                        break;
                        case Keys.W:
                            string[] paths = new string[this.monitors.Length];
                            for (int i = 0; i < this.monitors.Length; i++) {
                                paths[i] = Convert.ToString(this.monitors[i].imagePath());
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].showInfoOnMonitor("Setting as wallpaper");
                                }
                            }
                            Wallpaper wallpaper = new Wallpaper(this);
                            wallpaper.generateWallpaper(this.currentMonitor, paths);
                        break;
                        case Keys.X:
                            this.hideUpdateInfo();
                        break;
                        case Keys.D0:
                            this.currentMonitor = CM_ALL;
                            for (int i = 0; i < this.monitors.Length; i++) {
                                this.monitors[i].browser.Document.InvokeScript("identify");
                                this.monitors[i].showInfoOnMonitor("Offset (" + this.monitors[i].offset + ")");
                            }
                            break;
                        case Keys.D1:case Keys.D2:case Keys.D3:
                        case Keys.D4:case Keys.D5:case Keys.D6:
                        case Keys.D7:case Keys.D8:case Keys.D9:
                            int monitorId = e.KeyValue-49;
                            if (monitorId < this.monitors.Length) {
                                this.currentMonitor = monitorId;
                                this.monitors[monitorId].browser.Document.InvokeScript("identify");
                                this.monitors[monitorId].showInfoOnMonitor("Offset (" + this.monitors[monitorId].offset + ")");
                            }
                        break;
                        case Keys.NumPad4: case Keys.Left:
                            this.actionPrevious(this.getStep(e));
                        break;
                        case Keys.NumPad6: case Keys.Right:
                            this.actionNext(this.getStep(e));
                        break;
                        case Keys.NumPad2: case Keys.Down:
                            this.stopTimers();
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].timer.Stop();
                                    this.monitors[i].offsetImage(this.getStep(e));
                                    this.monitors[i].showImage(this.config.getPersistantBool("useTransitionsOnInput"));
                                    this.monitors[i].showInfoOnMonitor("v (" + this.monitors[i].offset + ")");
                                    this.monitors[i].startTimer();
                                }
                            }
                            this.startTimers();
                        break;
                        case Keys.NumPad8: case Keys.Up:
                            this.stopTimers();
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].timer.Stop();
                                    this.monitors[i].offsetImage(this.getStep(e)*-1);
                                    this.monitors[i].showImage(this.config.getPersistantBool("useTransitionsOnInput"));
                                    this.monitors[i].showInfoOnMonitor("^ (" + this.monitors[i].offset + ")");
                                    this.monitors[i].startTimer();
                                }
                            }
                            this.startTimers();
                        break;
                        case Keys.F2:
                        for (int i = 0; i < this.monitors.Length; i++) {
                            if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                this.monitors[i].renameFile();
                            }
                        }
                        break;
                        case Keys.F12:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    string path = this.monitors[i].saveDebug();
                                    if (e.Control) {
                                        if (Utils.RunTaskScheduler(@"OpenInExplorer" + Convert.ToString(i), "explorer.exe", "/e,/select,\"" + path + "\"")) {
                                            this.monitors[i].showInfoOnMonitor("Opened in Explorer Window", false, true);
                                        }
                                    }
                                }
                            }
                        break;
                        case Keys.OemOpenBrackets:
                        case Keys.OemCloseBrackets: 
                        case Keys.Oemplus:
                            this.stopTimers();
                            int deg = 0;
                            string message = "";
                            switch (KeyCode) {
                                case Keys.OemOpenBrackets: 
                                    deg = 270;
                                    message = "Rotating 270° clock wise";
                                break;
                                case Keys.OemCloseBrackets: 
                                    deg = 90;
                                    message = "Rotating 90° clock wise";
                                break;
                                case Keys.Oemplus: 
                                    deg = 180;
                                    message = "Upside down you're turning me";
                                break;
                            }

                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].info = message;
                                    this.monitors[i].showInfoOnMonitor(message, true, true);
                                    this.monitors[i].rotateImage(deg);
                                }
                            }
                            //this.fileNodes.toggleMetadataTransaction();
                            this.fileNodes.resetFilter();
                            this.startTimers();
                        break;
                        case Keys.Delete:
                        if (this.config.getPersistantBool("deleteKey")) {
                                this.pauseAll(false);
                                for (int i = 0; i < this.monitors.Length; i++) {
                                    if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                        bool deleteFile = true;
                                        string filename = this.monitors[i].imagePath();
                                        if (filename != null && filename.Length > 0 && File.Exists(filename)) {
                                            Cursor.Show();
                                            this.monitors[i].Focus();
                                            if (DialogResult.Yes == MessageBox.Show("Are you sure you want to delete '" + Path.GetFileName(filename) + "'?", "Confirm File Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)) {
                                                deleteFile = true;
                                            } else {
                                                deleteFile = false;
                                            }
                                            Cursor.Hide();
                                            if (deleteFile) {
                                                BackgroundWorker bgwDeleteFile = new BackgroundWorker();
                                                bgwDeleteFile.DoWork += new DoWorkEventHandler(DoWorkDeleteFile);
                                                bgwDeleteFile.RunWorkerAsync(new Object[] {i, filename});
                                            }
                                        }
                                    }
                                }
                                this.resumeAll(false);
                            }
                        break;
                        default:
        		            if (!e.Alt && !e.Control && !e.Shift) {
                                if (!this.config.getPersistantBool("onlyEscapeExits")) {
                                    this.OnExit();
                                }
                            }
                        break;
                    }
                    this.previousKey = e.KeyCode;
                }
            } 
        }
        /// <summary>
        /// Translates the WinForms key to Toolkit key and invokes status change
        /// </summary>
        /// <remarks>For modifier keys (Shift, Control, Alt) will invoke its Left... analog additionally</remarks>
        /// <param name="keyCode">WinForms key code to be translated</param>
        /// <param name="keyAction">delegate to invoke with translated key</param>
        private static void ProcessKeyEvent(FormsKeys keyCode, Action<Keys> keyAction)
        {
            Keys translatedKey;
            if (!_keysDictionaryForms.TryGetValue(keyCode, out translatedKey))
                translatedKey = Keys.None;

            keyAction(translatedKey);

            // XNA doesn't have handless modifier keys, so we will map general keys to left ones:
            // TODO: consider P/Invoke to get pressed keys and/or determine which key was pressed
            switch (translatedKey)
            {
                case Keys.Shift:
                    keyAction(Keys.LeftShift);
                    break;
                case Keys.Control:
                    keyAction(Keys.LeftControl);
                    break;
                case Keys.Alt:
                    keyAction(Keys.LeftAlt);
                    break;
            }
        }
Exemple #17
0
        void Game_Key(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            //if(e.KeyCode==System.Windows.Forms.Keys.Enter)

            if (e.KeyCode == System.Windows.Forms.Keys.Space)
               // Application.ExitThread();
            key_pressed = e.KeyCode;
               // move = true;
        }
 private static WinFormsKeys GetCorrectExtendedKey(WinFormsKeys virtualKey, long lParam)
 {
     if (virtualKey == WinFormsKeys.ControlKey)
     {
         // We check if the key is an extended key. Extended keys are R-keys, non-extended are L-keys.
         return (lParam & 0x01000000) == 0 ? WinFormsKeys.LControlKey : WinFormsKeys.RControlKey;
     }
     if (virtualKey == WinFormsKeys.ShiftKey)
     {
         // We need to check the scan code to check which SHIFT key it is.
         var scanCode = (lParam & 0x00FF0000) >> 16;
         return (scanCode != 36) ? WinFormsKeys.LShiftKey : WinFormsKeys.RShiftKey;
     }
     if (virtualKey == WinFormsKeys.Menu)
     {
         // We check if the key is an extended key. Extended keys are R-keys, non-extended are L-keys.
         return (lParam & 0x01000000) == 0 ? WinFormsKeys.LMenu : WinFormsKeys.RMenu;
     }
     return virtualKey;
 }
 /// <summary>
 /// Process Windows message and command key by calling ATF ProcessCmdKey with converted arguments.
 /// Returning false allows the key press to escape to IsInputKey, OnKeyDown, OnKeyUp, etc.
 /// Returning true means that this key press has been consumed by this method and this
 /// event is not passed on to any other methods or controls.</summary>
 /// <param name="msg">Windows message to process</param>
 /// <param name="keyData">Windows key data</param>
 /// <returns>False to allow the key press to escape to IsInputKey, OnKeyDown, OnKeyUp, etc.
 /// True to consume this key press, so this
 /// event is not passed on to any other methods or controls.</returns>
 protected override bool ProcessCmdKey(ref WfMessage msg, WfKeys keyData) 
 {
     AtfMessage atfMsg = MessageInterop.ToAtf(msg);
     return ProcessCmdKey(ref atfMsg, KeysInterop.ToAtf(keyData)); 
 }
Exemple #20
0
        public void ReceiveHotKey(System.Windows.Forms.Keys key)
        {
            switch (key)
            {
            case Keys.Up:
                UnSetCheSignal(1);
                UnSetCheSignal(2);
                UnSetCheSignal(3);
                SetCheSignal(0);
                break;

            case Keys.Down:
                UnSetCheSignal(0);
                UnSetCheSignal(2);
                UnSetCheSignal(3);
                SetCheSignal(1);
                break;

            case Keys.Z:
                UnSetCheSignal(0);
                UnSetCheSignal(1);
                UnSetCheSignal(3);
                SetCheSignal(2);
                break;

            case Keys.X:
                UnSetCheSignal(0);
                UnSetCheSignal(1);
                UnSetCheSignal(2);
                SetCheSignal(3);
                break;

            case Keys.D1:
                SwitchXianSignal(0);
                break;

            case Keys.D2:
                SwitchXianSignal(1);
                break;

            case Keys.D3:
                SwitchXianSignal(2);
                break;

            case Keys.D4:
                SwitchXianSignal(3);
                break;

            case Keys.D5:
                SwitchXianSignal(4);
                break;

            case Keys.D6:
                SwitchXianSignal(5);
                break;

            case Keys.D7:
                SwitchXianSignal(6);
                break;

            case Keys.D8:
                SwitchXianSignal(7);
                break;

            case Keys.Q:
                SwitchGanSignal(0);
                break;

            case Keys.W:
                SwitchGanSignal(1);
                break;

            case Keys.E:
                SwitchGanSignal(2);
                break;

            case Keys.A:
                SwitchGanSignal(3);
                break;

            case Keys.S:
                SwitchGanSignal(4);
                break;

            case Keys.D:
                SwitchGanSignal(5);
                break;

            case Keys.P:
                break;
            }
        }
Exemple #21
0
 public static extern int GetAsyncKeyState(System.Windows.Forms.Keys vKey);
Exemple #22
0
 static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            //    if (keyData != Keys.F2)
            //        return base.ProcessCmdKey(ref msg, keyData);

            //    if (msg.HWnd == this.txtKeHu1.Handle)
            //    {
            //        frmQueryCustomer.QueryCondition = this.txtKeHu1.Text;
            //        frmQueryCustomer Customer = new frmQueryCustomer();

            //        if (DialogResult.OK == Customer.ShowDialog())
            //        {
            //            this.txtKeHu1.Text = frmQueryCustomer.CustomerID;
            //        }
            //    }
            //    else if (msg.HWnd == this.txtKeHu2.Handle)
            //    {
            //        frmQueryCustomer.QueryCondition = this.txtKeHu2.Text;
            //        frmQueryCustomer Customer = new frmQueryCustomer();

            //        if (DialogResult.OK == Customer.ShowDialog())
            //        {
            //            this.txtKeHu2.Text = frmQueryCustomer.CustomerID;
            //        }
            //    }
            //    else if (msg.HWnd == this.txtYYS1.Handle)
            //    {
            //        frmQueryDepartment.QueryCondition = this.txtYYS1.Text;
            //        frmQueryDepartment Department = new frmQueryDepartment();

            //        if (DialogResult.OK == Department.ShowDialog())
            //        {
            //            this.txtYYS1.Text = frmQueryDepartment.DepartmentID;
            //        }
            //    }
            //    else if (msg.HWnd == this.txtYYS2.Handle)
            //    {
            //        frmQueryDepartment.QueryCondition = this.txtYYS2.Text;
            //        frmQueryDepartment Department = new frmQueryDepartment();

            //        if (DialogResult.OK == Department.ShowDialog())
            //        {
            //            this.txtYYS2.Text = frmQueryDepartment.DepartmentID;
            //        }
            //    }
            //    else if (msg.HWnd == this.txtChanPin1.Handle)
            //    {
            //        frmQueryInventory.QueryCondition = this.txtChanPin1.Text;
            //        frmQueryInventory Inventory = new frmQueryInventory();

            //        if (DialogResult.OK == Inventory.ShowDialog())
            //        {
            //            this.txtChanPin1.Text = frmQueryInventory.InvCode;
            //        }
            //    }
            //    else if (msg.HWnd == this.txtChanPin2.Handle)
            //    {
            //        frmQueryInventory.QueryCondition = this.txtChanPin2.Text;
            //        frmQueryInventory Inventory = new frmQueryInventory();

            //        if (DialogResult.OK == Inventory.ShowDialog())
            //        {
            //            this.txtChanPin2.Text = frmQueryInventory.InvCode;
            //        }
            //    }

            return(base.ProcessCmdKey(ref msg, keyData));
        }
Exemple #24
0
 /// <summary>
 /// Obs³uga wciœniêcia klawisza klawiatury
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Game_Key(object sender, System.Windows.Forms.KeyEventArgs e)
 {
     key_pressed = e.KeyCode;
     move = true;
 }
 private void OnKeyEvent(WinFormsKeys keyCode, bool isKeyUp)
 {
     Keys key;
     if (mapKeys.TryGetValue(keyCode, out key) && key != Keys.None)
     {
         var type = isKeyUp ? InputEventType.Up : InputEventType.Down;
         lock (KeyboardInputEvents)
         {
             KeyboardInputEvents.Add(new KeyboardInputEvent { Key = key, Type = type });
         }
     }
 }
Exemple #26
0
 internal KeyPressedEventArgs(ModifierKeys modifier, Keys key)
 {
     _modifier = modifier;
     _key = key;
 }
Exemple #27
0
        private bool myDataGrid1_myKeyDown(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            try
            {
                DataTable tb         = (DataTable)this.myDataGrid1.DataSource;
                int       nrow       = this.myDataGrid1.CurrentCell.RowNumber;
                int       ncol       = this.myDataGrid1.CurrentCell.ColumnNumber;
                int       nkey       = Convert.ToInt32(keyData);
                string    columnName = this.myDataGrid1.TableStyles[0].GridColumnStyles[ncol].HeaderText.Trim();
                if (nrow > tb.Rows.Count - 1)
                {
                    return(true);
                }

//				if (Convert.ToInt32(Convertor.IsNull(tb.Rows[nrow]["fid"].ToString(),"0"))==0)
//				{
//					tb.Rows[nrow]["所属上级编目"]=this.treeView1.SelectedNode.Text;
//					tb.Rows[nrow]["fid"]=this.treeView1.SelectedNode.Tag;
//				}


                if (columnName.Trim() == "名称" && nkey == 13)
                {
                    string coltext = "";
                    DataGridTextBoxColumn txtCol = (DataGridTextBoxColumn)this.myDataGrid1.TableStyles[0].GridColumnStyles[ncol];
                    coltext = txtCol.TextBox.Text;
                    if (coltext.Trim() == "")
                    {
                        return(true);
                    }

                    if (nrow >= tb.Rows.Count - 1)
                    {
//						DataRow row=tb.NewRow();
//						row["序号"]=nrow+2;
//						row["禁用"]=(short)0;
//						tb.Rows.Add(row);
                        AddNewRow(tb, this.treeView1.SelectedNode);
                    }

                    tb.Rows[nrow]["名称"]  = coltext;
                    tb.Rows[nrow]["拼音码"] = PubStaticFun.GetPYWBM(coltext, 0);
                    tb.Rows[nrow]["五笔码"] = PubStaticFun.GetPYWBM(coltext, 1);
                }

                if (nkey == 13 && columnName != "禁用")
                {
                    this.myDataGrid1.CurrentCell = new DataGridCell(nrow, ncol + 1);
                }
                if (nkey == 13 && columnName == "禁用")
                {
                    this.myDataGrid1.CurrentCell = new DataGridCell(nrow + 1, 2);
                }

                if (columnName.Trim() == "所属上级编目" && nkey != 13)
                {
                    Point point = new Point(this.myDataGrid1.GetCellBounds(nrow, ncol).Left - 50, this.myDataGrid1.GetCellBounds(nrow, ncol).Top + this.myDataGrid1.Top + this.myDataGrid1.GetCellBounds(nrow, ncol).Height);
                    this.treeView2.Location  = point;
                    this.treeView2.Visible   = true;
                    this.myDataGrid1.Enabled = false;
                }

                return(false);
            }

            catch (System.Exception err)
            {
                MessageBox.Show("错误" + err.Message);
                return(false);
            }
        }
Exemple #28
0
 static public extern short GetKeyState(System.Windows.Forms.Keys key_spesial);
Exemple #29
0
 public static extern short GetAsyncKeyState(
     System.Windows.Forms.Keys vKey);    // The keycode to poll for
Exemple #30
0
        /// <summary>
        /// implement IMessageFilter interface
        /// </summary>
        /// <param name="m">The message to be dispatched.</param>
        /// <returns>true to filter the message and stop it from being dispatched;
        /// false to allow the message to continue to the next filter or control.</returns>
        public bool PreFilterMessage(ref Message m)
        {
            if (!modelPictureBox.Focused)
            {
                return(false);
            }

            if (m.Msg == WM_KEYDOWN)
            {
                System.Windows.Forms.Keys k = (System.Windows.Forms.Keys)(int) m.WParam;
                KeyEventArgs e = new KeyEventArgs(k);
                switch (e.KeyCode)
                {
                case Keys.Left:
                    m_graphicsData.RotateY(true);
                    break;

                case Keys.Right:
                    m_graphicsData.RotateY(false);
                    break;

                case Keys.Up:
                    m_graphicsData.RotateX(true);
                    break;

                case Keys.Down:
                    m_graphicsData.RotateX(false);
                    break;

                case Keys.PageUp:
                    m_graphicsData.RotateZ(true);
                    break;

                case Keys.PageDown:
                    m_graphicsData.RotateZ(false);
                    break;

                case Keys.S:
                    modelPictureBox.MoveY(true);
                    break;

                case Keys.W:
                    modelPictureBox.MoveY(false);
                    break;

                case Keys.A:
                    modelPictureBox.MoveX(true);
                    break;

                case Keys.D:
                    modelPictureBox.MoveX(false);
                    break;

                case Keys.Home:
                    modelPictureBox.Scale(true);
                    break;

                case Keys.End:
                    modelPictureBox.Scale(false);
                    break;

                default:
                    break;
                }
                return(true);
            }
            return(false);
        }
Exemple #31
0
 public static bool BasildiMi(System.Windows.Forms.Keys tus)
 {
     return(0 != (GetAsyncKeyState((int)tus) & 0x8000));
 }
Exemple #32
0
        public void ReceiveHotKey(System.Windows.Forms.Keys key)
        {
            switch (key)
            {
            case Keys.Up:
                UnSetCheSignal(1);
                UnSetCheSignal(2);
                UnSetCheSignal(3);
                SetCheSignal(0);
                break;

            case Keys.Down:
                UnSetCheSignal(0);
                UnSetCheSignal(2);
                UnSetCheSignal(3);
                SetCheSignal(1);
                break;

            case Keys.Space:
                UnSetCheSignal(0);
                UnSetCheSignal(1);
                UnSetCheSignal(3);
                SetCheSignal(2);
                break;

            case Keys.X:
                UnSetCheSignal(0);
                UnSetCheSignal(1);
                UnSetCheSignal(2);
                SetCheSignal(3);
                break;

            case Keys.D1:
                SwitchXianSignal(0);
                break;

            case Keys.D2:
                SwitchXianSignal(1);
                break;

            case Keys.D3:
                SwitchXianSignal(2);
                break;

            case Keys.D4:
                SwitchXianSignal(3);
                break;

            case Keys.D5:
                SwitchXianSignal(4);
                break;

            case Keys.D6:
                SwitchXianSignal(5);
                break;

            case Keys.D7:
                SwitchXianSignal(6);
                //if (_carType == CheType.BigCar)
                //    signal.SwitchBit(3, s_gan_loc);
                //else
                //    signal.SwitchBit(3, s_gan_loc);
                break;

            case Keys.D8:
                SwitchXianSignal(7);
                //if (_carType == CheType.BigCar)
                //    signal.SwitchBit(5, b_gan_loc);
                //else
                //    signal.SwitchBit(5, s_gan_loc);
                break;

            case Keys.D9:
                SwitchXianSignal(8);
                //if (_carType == CheType.BigCar)
                //    signal.SwitchBit(3, b_gan_loc);
                //else
                //    signal.SwitchBit(3, b_gan_loc);
                break;

            case Keys.Q:
                SwitchGanSignal(0);
                break;

            case Keys.W:
                SwitchGanSignal(1);
                break;

            case Keys.E:
                SwitchGanSignal(2);
                break;

            case Keys.A:
                SwitchGanSignal(3);
                break;

            case Keys.S:
                SwitchGanSignal(4);
                break;

            case Keys.D:
                SwitchGanSignal(5);
                break;

            case Keys.P:
                break;
            }
        }
Exemple #33
0
        private void TabButton_OnClick(object sender,
                                       System.EventArgs e)
        {
            if (sender == null || !typeof(TabButton).IsAssignableFrom(sender.GetType()))
            {
                return;
            }

            TabButton currentButton = (TabButton)sender;

            if (!m_Multiselect)
            {
                m_LastShiftKeyTab   = null;
                this.SelectedButton = currentButton;
            }
            else
            {
                // Multiselect

                System.Windows.Forms.Keys keys = ModifierKeys;
                bool bCtrlPressed  = (keys & Keys.Control) == Keys.Control;
                bool bShiftPressed = (keys & Keys.Shift) == Keys.Shift;

                if (bCtrlPressed)
                {
                    m_LastShiftKeyTab = null;

                    if (currentButton != null)
                    {
                        currentButton.Checked = !currentButton.Checked;
                    }

                    if (m_ActiveTab == currentButton)
                    {
                        if (!currentButton.Checked)
                        {
                            m_ActiveTab = null;

                            // m_ActiveTab = first checked
                            foreach (Control c in Controls)
                            {
                                if (typeof(TabButton).IsAssignableFrom(c.GetType()))
                                {
                                    TabButton tabButton = (TabButton)c;
                                    if (tabButton.Visible && tabButton.Checked)
                                    {
                                        m_ActiveTab = tabButton;
                                        break;
                                    }
                                }
                            }                             // foreach
                        }
                    }
                    else
                    {
                        m_ActiveTab = currentButton;
                    }
                }
                else if (bShiftPressed && currentButton != null)
                {
                    // TODO: ShiftKeyUp -- m_ActiveTab = currentButton
                    m_LastShiftKeyTab = currentButton;

                    int first = -1, last = -1, m = -1;

                    // has no selection ? m_ActiveTab = first item from container
                    if (m_ActiveTab == null)
                    {
                        foreach (Control c in Controls)
                        {
                            if (typeof(TabButton).IsAssignableFrom(c.GetType()))
                            {
                                TabButton tabButton = (TabButton)c;
                                if (tabButton.Visible)
                                {
                                    m_ActiveTab = tabButton;
                                    break;
                                }
                            }
                        }
                    }

                    // get btn range to be checked
                    if (m_Vertical)
                    {
                        first = currentButton.Top + currentButton.Height / 2;
                        last  = m_ActiveTab.Top + m_ActiveTab.Height / 2;
                    }
                    else
                    {
                        first = currentButton.Left + currentButton.Width / 2;
                        last  = m_ActiveTab.Left + m_ActiveTab.Width / 2;
                    }

                    if (first > last)
                    {
                        m     = last;
                        last  = first;
                        first = m;
                    }

                    // check btns
                    foreach (Control c in Controls)
                    {
                        if (typeof(TabButton).IsAssignableFrom(c.GetType()))
                        {
                            TabButton tabButton = (TabButton)c;
                            if (tabButton.Visible)
                            {
                                if (m_Vertical)
                                {
                                    m = tabButton.Top + tabButton.Height / 2;
                                }
                                else
                                {
                                    m = tabButton.Left + tabButton.Width / 2;
                                }

                                if (first <= m && last >= m)
                                {
                                    tabButton.Checked = true;
                                }
                                else
                                {
                                    tabButton.Checked = false;
                                }
                            }
                        }
                    }                     // foreach
                }
                else
                {
                    foreach (Control c in Controls)
                    {
                        if (typeof(TabButton).IsAssignableFrom(c.GetType()))
                        {
                            TabButton tabButton = (TabButton)c;
                            tabButton.Checked = currentButton == tabButton;
                        }
                    }

                    m_ActiveTab = currentButton;
                }

                RefreshLayout();
                OnSelectedTabChanged(System.EventArgs.Empty);
            }
        }
 public KeyMap(int code, System.Windows.Forms.Keys key, string name, string settingName, bool valid)
 {
   this.Code = code;
   this.Key = key;
   this.SettingName = settingName;
   this.Name = name;
   this.Valid = valid;
 }
Exemple #35
0
 public HotKeyEventArgs(System.Windows.Forms.Keys key, KeyModifiers modifiers)
 {
     this.Key       = key;
     this.Modifiers = modifiers;
 }
Exemple #36
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (isStarted)
            {

                // Allows the game to exit
                if (!IsPaused)
                {
                    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                        this.Exit();

                    updateLabel(gameTime.TotalGameTime.Minutes - lastUpdateMinutes, gameTime.TotalGameTime.Seconds - lastUpdateSeconds);
                    game_map.Update(gameTime);
                    lastUpdateMinutes = gameTime.TotalGameTime.Minutes;
                    lastUpdateSeconds = gameTime.TotalGameTime.Seconds;

                    if (key_pressed == System.Windows.Forms.Keys.None)
                    {
                        if (move)
                        {
                            move = false;
                            game_map.MoveVandal(direction.none);
                        }
                    }

                    else if (key_pressed == player.KeyboardSettings.Up)
                    {
                        game_map.MoveVandal(direction.up);
                    }
                    else if (key_pressed == player.KeyboardSettings.Down)
                    {
                        game_map.MoveVandal(direction.down);
                    }
                    else if (key_pressed == player.KeyboardSettings.Left)
                    {
                        game_map.MoveVandal(direction.left);
                    }
                    else if (key_pressed == player.KeyboardSettings.Right)
                    {
                        game_map.MoveVandal(direction.right);
                    }
                    else if (key_pressed == player.KeyboardSettings.Block)
                    {
                        game_map.GetVandal().changeDirectionToNext(game_map);
                    }
                    else if (key_pressed == player.KeyboardSettings.Dynamite)
                    {
                        if (player.Dynamite > 0)
                        {
                            game_map.GetVandal().LeftDynamite(game_map, gameTime);
                            key_pressed = System.Windows.Forms.Keys.None;
                        }
                        else
                        {
                            SoundEffect null_sound = Content.Load<SoundEffect>("Audio\\null_sound");
                            if (!player.AudioSettings.IsMuted)
                            {
                                SoundEffect.MasterVolume = (float)player.AudioSettings.SoundVolume;
                                null_sound.Play();
                            }

                        }
                    }
                    else if (key_pressed == player.KeyboardSettings.Pause)
                    {

                        PauseGame();
                    }
                    else if (key_pressed == player.KeyboardSettings.Racket)
                    {
                        if (player.Rackets > 0)
                            game_map.GetVandal().AttackWithRacket(game_map);
                        else
                        {
                            SoundEffect null_sound = Content.Load<SoundEffect>("Audio\\null_sound");
                            if (!player.AudioSettings.IsMuted)
                            {
                                SoundEffect.MasterVolume = (float)player.AudioSettings.SoundVolume;
                                null_sound.Play();
                            }
                        }
                    }

                    if (game_map.GetVandal().level_up)
                    {
                        int current_level = game_map.gameLevel;
                        if (current_level < 5)
                        {
                            //aktualizacja maksymalnego dopuszczalnego pzoiomu gry
                            if (player.MaxEnabledLevel < current_level + 1)
                            {
                                player.MaxEnabledLevel = current_level + 1;
                                Form.choose_level_panel.EnableTillLevel(player.MaxEnabledLevel);
                            }

                            //ustawianie poziomu inteligencji - jest ta funkcjonalnosc jest wlaczona
                            if (player.CheckIntelligence)
                            {
                                if (player.Points < 500 * current_level)
                                    player.IntelligenceLevel = 0;
                                if (player.Points >= 500 * current_level && player.Points < 900 * current_level)
                                    player.IntelligenceLevel = 1;
                                else player.IntelligenceLevel = 2;
                            }

                            game_map = new Map.Map(tile_size, map_width, map_height, this.Content, player, current_level + 1);

                        }
                        else
                        {
                            SaveHighScore();
                            Win();
                        }
                    }
                }
                if (!game_map.GetVandal().is_alive)
                {
                    IsPaused = true;
                    SaveHighScore();
                    GameOver();
                    game_map.GetVandal().is_alive = true;
                }

                {
                    base.Update(gameTime);

                    lastUpdateMinutes = gameTime.TotalGameTime.Minutes;
                    lastUpdateSeconds = gameTime.TotalGameTime.Seconds;
                }
            }
        }
Exemple #37
0
 public override void OnMouseDown(PointF location, System.Windows.Forms.Keys keys, System.Windows.Forms.MouseButtons buttons)
 {
     base.OnMouseDown(location, keys, buttons);
     path = new GraphicsPath();
     Project.ClearSelection();
 }
Exemple #38
0
        /// <summary>
        /// Create a list view item describing this HidEvent
        /// </summary>
        /// <returns></returns>
        public ListViewItem ToListViewItem()
        {
            string usageText   = "";
            string inputReport = null;

            foreach (ushort usage in Usages)
            {
                if (usageText != "")
                {
                    //Add a separator
                    usageText += ", ";
                }

                //Try to get a name for that usage
                string name = "";
                if (Enum.IsDefined(typeof(Hid.UsagePage), UsagePage))
                {
                    UsagePage usagePage = (UsagePage)UsagePage;

                    try
                    {
                        name = Enum.GetName(Utils.UsageType(usagePage), usage);
                    }
                    catch
                    {
                    }
                }

                if (name == null || name.Equals("") || Device.IsGamePad) //Gamepad buttons do not belong to Usage enumeration, they are just ordinal
                {
                    name = usage.ToString("X2");
                }
                usageText += name;
            }

            // Get input report for generic HID events
            if (IsGeneric)
            {
                inputReport = InputReportString();
            }

            //If we are a gamepad display axis and dpad values
            if (Device != null && Device.IsGamePad)
            {
                //uint dpadUsageValue = GetUsageValue((ushort)Hid.UsagePage.GenericDesktopControls, (ushort)Hid.Usage.GenericDesktop.HatSwitch);
                //usageText = dpadUsageValue.ToString("X") + " (dpad), " + usageText;

                if (usageText != "")
                {
                    //Add a separator
                    usageText += " (Buttons)";
                }

                if (usageText != "")
                {
                    //Add a separator
                    usageText += ", ";
                }

                usageText += GetDirectionPadState().ToString();

                //For each axis
                foreach (KeyValuePair <HIDP_VALUE_CAPS, uint> entry in UsageValues)
                {
                    if (entry.Key.IsRange)
                    {
                        continue;
                    }

                    //Get our usage type
                    Type usageType = Utils.UsageType((UsagePage)entry.Key.UsagePage);
                    if (usageType == null)
                    {
                        //Unknown usage type
                        //TODO: check why this is happening on Logitech rumble gamepad 2.
                        //Probably some of our axis are hiding in there.
                        continue;
                    }

                    //Get the name of our axis
                    string name = Enum.GetName(usageType, entry.Key.NotRange.Usage);

                    if (usageText != "")
                    {
                        //Add a separator
                        usageText += ", ";
                    }
                    usageText += entry.Value.ToString("X") + " (" + name + ")";
                }
            }
            //Handle keyboard events
            else if (IsKeyboard)
            {
                //Get the virtual key
                System.Windows.Forms.Keys vKey = (Keys)RawInput.keyboard.VKey;
                usageText = vKey.ToString() + " -";

                //Get the key flag
                if (IsButtonUp)
                {
                    usageText += " UP";
                }
                else if (IsButtonDown)
                {
                    usageText += " DOWN";
                }

                if (RawInput.keyboard.Flags.HasFlag(RawInputKeyFlags.RI_KEY_E0))
                {
                    usageText += " E0";
                }

                if (RawInput.keyboard.Flags.HasFlag(RawInputKeyFlags.RI_KEY_E1))
                {
                    usageText += " E1";
                }

                if (HasModifierShift)
                {
                    usageText += " SHIFT";
                }

                if (HasModifierControl)
                {
                    usageText += " CTRL";
                }

                if (HasModifierAlt)
                {
                    usageText += " ALT";
                }

                if (HasModifierWindows)
                {
                    usageText += " WIN";
                }


                //Put our scan code into our input report field
                inputReport = "0x" + RawInput.keyboard.MakeCode.ToString("X4");
            }

            //Now create our list item
            ListViewItem item = new ListViewItem(new[] { usageText, inputReport, UsagePageNameAndValue(), UsageCollectionNameAndValue(), RepeatCount.ToString(), Time.ToString("HH:mm:ss:fff"), IsBackground.ToString() });

            return(item);
        }
Exemple #39
0
        static Keys Find(swf.Keys key)
        {
            Keys mapped;

            return(keymap.TryGetValue(key, out mapped) ? mapped : Keys.None);
        }
Exemple #40
0
 bool isKeyUp(System.Windows.Forms.Keys key)
 {
     // TODO: implement
     return(false);
 }
Exemple #41
0
        private bool Instance_ProcessCmdKeyCallback(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            if (keyData == (Keys.Alt | Keys.A))
            {
                MainV2.comPort.setMode("Auto");
                return(true);
            }
            if (keyData == (Keys.Alt | Keys.G))
            {
                MainV2.comPort.setMode("Loiter");
                return(true);
            }
            if (keyData == (Keys.Alt | Keys.U))
            {
                MainV2.comPort.setMode("AltHold");
                return(true);
            }
            if (keyData == (Keys.Alt | Keys.S))
            {
                MainV2.comPort.setMode("Stabalize");
                return(true);
            }
            if (keyData == (Keys.Alt | Keys.H))
            {
                MainV2.comPort.setMode("RTL");
                return(true);
            }

            if (keyData == (Keys.Alt | Keys.T))
            {
                MainV2.comPort.doCommand((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, MAVLink.MAV_CMD.TAKEOFF, 0, 0, 0, 0, 0, 0, 2);
                return(true);
            }
            if (keyData == (Keys.Alt | Keys.L))
            {
                MainV2.comPort.doCommand((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, MAVLink.MAV_CMD.LAND, 0, 0, 0, 0, 0, 0, 0);
                return(true);
            }

            if (keyData == (Keys.Alt | Keys.D0))
            {
                MainV2.comPort.SendRCOverride(MainV2.comPort.MAV.sysid, MainV2.comPort.MAV.compid, 0, 0, 1000, 0, 0, 0,
                                              0, 0);
                return(true);
            }

            if (keyData == (Keys.Alt | Keys.F1))
            {
                //MainV2.comPort.doCommand((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, MAVLink.MAV_CMD.DO_SET_SERVO, 1, MainV2.comPort.MAV., 0, 0, 0, 0, 0, true);
                return(true);
            }

            return(false);
        }
 static public extern short GetKeyState(System.Windows.Forms.Keys nVirtKey);
        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                // ON ENTER KEY, GO TO THE NEXT CELL.
                // WHEN THE CURSOR REACHES THE LAST COLUMN, CARRY IT ON TO THE NEXT ROW.

                if (ActiveControl.Name == "grid_Master")
                {
                    // CHECK IF ITS THE LAST COLUMN
                    if (grid_Master.CurrentCell.ColumnIndex == grid_Master.ColumnCount - 1)
                    {
                        // GO TO THE FIRST COLUMN, NEXT ROW.
                        grid_Master.CurrentCell =
                            grid_Master.Rows[grid_Master.CurrentCell.RowIndex + 1]
                            .Cells[0];
                    }
                    else
                    {
                        // NEXT COLUMN.
                        grid_Master.CurrentCell =
                            grid_Master.Rows[grid_Master.CurrentRow.Index]
                            .Cells[grid_Master.CurrentCell.ColumnIndex + 1];
                    }

                    return(true);
                }
                else if (ActiveControl is DataGridViewTextBoxEditingControl)
                {
                    // SHOW THE COMBOBOX WHEN FOCUS IS ON A CELL CORRESPONDING TO THE "QUALIFICATION" COLUMN.
                    if (grid_Master.Columns[grid_Master.CurrentCell.ColumnIndex].Name == "PresentAddress")
                    {
                        grid_Master.CurrentCell =
                            grid_Master.Rows[grid_Master.CurrentRow.Index]
                            .Cells[grid_Master.CurrentCell.ColumnIndex + 1];

                        // SHOW COMBOBOX.
                        Show_Combobox(grid_Master.CurrentRow.Index,
                                      grid_Master.CurrentCell.ColumnIndex);

                        SendKeys.Send("{F4}");      // DROP DOWN THE LIST.
                        return(true);
                    }
                    else
                    {
                        // CHECK IF ITS THE LAST COLUMN.
                        if (grid_Master.CurrentCell.ColumnIndex == grid_Master.ColumnCount - 1)
                        {
                            // GO TO THE FIRST COLUMN, NEXT ROW.
                            grid_Master.CurrentCell =
                                grid_Master.Rows[grid_Master.CurrentCell.RowIndex + 1]
                                .Cells[0];
                        }
                        else
                        {
                            // NEXT COLUMN.
                            grid_Master.CurrentCell = grid_Master.Rows[grid_Master.CurrentRow.Index].Cells[grid_Master.CurrentCell.ColumnIndex + 1];
                        }
                        return(true);
                    }
                }
                else if (ActiveControl.Name == "ComboBox1")
                {
                    // HIDE THE COMBOBOX AND ASSIGN COMBO'S VALUE TO THE CELL.
                    ComboBox1.Visible = false;

                    grid_Master.Focus();

                    // ONCE THE COMBO IS SET AS INVISIBLE, SET FOCUS BACK TO THE GRID.
                    // (IMPORTANT)
                    grid_Master[grid_Master.CurrentCell.ColumnIndex, grid_Master.CurrentRow.Index].Value = ComboBox1.Text;
                    grid_Master.CurrentCell = grid_Master.Rows[grid_Master.CurrentRow.Index].Cells[grid_Master.CurrentCell.ColumnIndex + 1];
                }
                else
                {
                    SendKeys.Send("{TAB}");
                }
                return(true);
            }
            else if (keyData == Keys.Escape)            // PRESS ESCAPE TO HIDE THE COMBOBOX.
            {
                if (ActiveControl.Name == "ComboBox1")
                {
                    ComboBox1.Text    = "";
                    ComboBox1.Visible = false;

                    grid_Master.CurrentCell =
                        grid_Master.Rows[grid_Master.CurrentCell.RowIndex].Cells[grid_Master.CurrentCell.ColumnIndex];
                    grid_Master.Focus();
                }
                return(true);
            }
            else
            {
                return(base.ProcessCmdKey(ref msg, keyData));
            }
        }
Exemple #44
0
 private static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey); // Keys enumeration
Exemple #45
0
 /// <summary>
 /// To tell the control to receive all possible keys it can.
 /// </summary>
 /// <param name="keyData"></param>
 /// <returns>true to receive all possible key events.</returns>
 protected override bool IsInputKey(System.Windows.Forms.Keys keyData)
 {
     return(true);
 }
 public static bool IsKeyDown(WinForms.Keys key) => KeyStates.Down == (GetKeyState(key) & KeyStates.Down);
 public static bool IsKeyToggled(WinForms.Keys key) => KeyStates.Toggled == (GetKeyState(key) & KeyStates.Toggled);
Exemple #48
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (!IsPaused)
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    this.Exit();

                updateLabel(gameTime.TotalGameTime.Minutes - lastUpdateMinutes, gameTime.TotalGameTime.Seconds - lastUpdateSeconds);

                game_map.Update(gameTime);

                if (key_pressed == System.Windows.Forms.Keys.None)
                {
                    if (move)
                    {
                        // if (gameTime.TotalGameTime.Milliseconds % 20 == 0)
                        // vandal.SetFinalPosition(game_map);
                        move = false;
                        game_map.MoveVandal(direction.none);
                    }
                }

                else if (key_pressed == player.KeyboardSettings.Up)
                {
                    if (gameTime.TotalGameTime.Milliseconds % 20 == 0)
                        game_map.MoveVandal(direction.up);
                }
                else if (key_pressed == player.KeyboardSettings.Down)
                {

                   if (gameTime.TotalGameTime.Milliseconds % 20 == 0)
                        game_map.MoveVandal(direction.down);

                }
                else if (key_pressed == player.KeyboardSettings.Left)
                {

                    if (gameTime.TotalGameTime.Milliseconds % 20 == 0)
                    {
                        game_map.MoveVandal(direction.left);
                    }
                }
                else if (key_pressed == player.KeyboardSettings.Right)
                {
                    if (gameTime.TotalGameTime.Milliseconds % 20 == 0)
                        game_map.MoveVandal(direction.right);
                }
                else if (key_pressed == player.KeyboardSettings.Block)
                {
                    if (gameTime.TotalGameTime.Milliseconds % 20 == 0)
                        game_map.GetVandal().changeDirectionToNext(game_map);
                }
                else if (key_pressed == player.KeyboardSettings.Dynamite)
                {
                    if (player.Dynamite > 0)
                    {
                        game_map.GetVandal().LeftDynamite(game_map, gameTime);
                        key_pressed = System.Windows.Forms.Keys.None;
                    }
                    else
                    {
                        SoundEffect null_sound = Content.Load<SoundEffect>("Audio\\null_sound");
                        SoundEffect.MasterVolume = (float)player.AudioSettings.SoundVolume;
                        null_sound.Play();

                    }
                }
                else if (key_pressed == player.KeyboardSettings.Pause)
                {

                    PauseGame();
                }
                else if (key_pressed == player.KeyboardSettings.Racket)
                {
                    if (player.Rackets > 0)
                        game_map.GetVandal().AttackWithRacket(game_map);
                    else
                    {
                        SoundEffect.MasterVolume = (float)player.AudioSettings.SoundVolume;
                        SoundEffect null_sound = Content.Load<SoundEffect>("Audio\\null_sound");
                        null_sound.Play();
                    }
                }

                // vandal.LoadCurrentTexture(game_map);

                if (game_map.GetVandal().level_up)
                {
                    int current_level = game_map.gameLevel;
                    if (current_level < 5)
                    {
                        game_map = new Map.Map(tile_size, map_width, map_height, this.Content, player,current_level + 1);
                    }
                    else
                    {
                        SaveHighScore();

                        Win();
                    }
                }
            }
            if (!game_map.GetVandal().is_alive)
            {
                SaveHighScore();
                GameOver();
            }

            else
            {
                base.Update(gameTime);

                lastUpdateMinutes = gameTime.TotalGameTime.Minutes;
                lastUpdateSeconds = gameTime.TotalGameTime.Seconds;
            }
        }
Exemple #49
0
 public static bool IsKeyPushedDown(System.Windows.Forms.Keys vKey)
 {
     return(0 != (GetAsyncKeyState(vKey) & 0x8000));
 }
Exemple #50
0
 /// <summary>
 /// Obs³uga zwolnienia klawisza klawiatury
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void Game_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
 {
     key_pressed = System.Windows.Forms.Keys.None;
 }
Exemple #51
0
        static int GetKeyCode(SWF.KeyEventArgs e)
        {
            SWF.Keys code = e.KeyData & SWF.Keys.KeyCode;
            if ((code >= SWF.Keys.A) && (code <= SWF.Keys.Z))
            {
                return(KEYCODE_A + (code - SWF.Keys.A));
            }
            else if ((code >= SWF.Keys.D0) && (code <= SWF.Keys.D9))
            {
                return(KEYCODE_0 + (code - SWF.Keys.D0));
            }
            else if ((code >= SWF.Keys.NumPad0) && (code <= SWF.Keys.NumPad9))
            {
                return(KEYCODE_NUMPAD_0 + (code - SWF.Keys.NumPad9));
            }
            else if ((code >= SWF.Keys.F1) && (code <= SWF.Keys.F24))
            {
                return(KEYCODE_F1 + (code - SWF.Keys.F1));
            }
            switch (code)
            {
            case SWF.Keys.Back:
                return(KEYCODE_BACK);

            case SWF.Keys.Tab:
                return(KEYCODE_TAB);

            case SWF.Keys.Clear:
                return(KEYCODE_CLEAR);

            case SWF.Keys.Enter:
                return(KEYCODE_ENTER);

            case SWF.Keys.Escape:
                return(KEYCODE_ESCAPE);

            case SWF.Keys.PageUp:
                return(KEYCODE_PAGE_UP);

            case SWF.Keys.PageDown:
                return(KEYCODE_PAGE_DOWN);

            case SWF.Keys.Home:
                return(KEYCODE_HOME);

            case SWF.Keys.Left:
                return(KEYCODE_DPAD_LEFT);

            case SWF.Keys.Right:
                return(KEYCODE_DPAD_RIGHT);

            case SWF.Keys.Up:
                return(KEYCODE_DPAD_UP);

            case SWF.Keys.Down:
                return(KEYCODE_DPAD_DOWN);

            case SWF.Keys.Insert:
                return(KEYCODE_INSERT);

            case SWF.Keys.Delete:
                return(KEYCODE_FORWARD_DEL);

            case SWF.Keys.Multiply:
                return(KEYCODE_NUMPAD_MULTIPLY);

            case SWF.Keys.Add:
                return(KEYCODE_NUMPAD_ADD);

            case SWF.Keys.Subtract:
                return(KEYCODE_NUMPAD_SUBTRACT);

            case SWF.Keys.Divide:
                return(KEYCODE_NUMPAD_DIVIDE);

            case SWF.Keys.Space:
                return(KEYCODE_SPACE);

            case SWF.Keys.OemBackslash:
                return(KEYCODE_BACKSLASH);

            case SWF.Keys.Oemcomma:
                return(KEYCODE_COMMA);

            case SWF.Keys.OemPeriod:
                return(KEYCODE_PERIOD);

            case SWF.Keys.OemQuestion:
                return(KEYCODE_SLASH);

            case SWF.Keys.OemMinus:
                return(KEYCODE_MINUS);

            case SWF.Keys.Oemplus:
                return(KEYCODE_PLUS);

            case SWF.Keys.Oem4:
                return(KEYCODE_LEFT_BRACKET);

            case SWF.Keys.OemCloseBrackets:
                return(KEYCODE_RIGHT_BRACKET);

            case SWF.Keys.OemSemicolon:
                return(KEYCODE_SEMICOLON);

            case SWF.Keys.Oem7:
                return(KEYCODE_APOSTROPHE);

            case SWF.Keys.OemPipe:
                return(KEYCODE_POUND);

            case SWF.Keys.Oem3:
                return(KEYCODE_GRAVE);

            default:
                Console.WriteLine("GET KEY CODE: {0} {1}", code, (int)code);
                return(-1);
            }
        }
Exemple #52
0
 public KeyStroke(Keys KeyCode, bool Ctrl, bool Alt, bool Shift)
 {
     this.KeyCode = KeyCode;
     this.Ctrl = Ctrl;
     this.Alt = Alt;
     this.Shift = Shift;
 }
Exemple #53
0
        public void RegisterGlobalHotKey(ModifierKeys modifier, Keys key, Form mainForm)
        {
            try
            {
                _currentId = _currentId + 1;

                if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
                    TraceOps.Out("Couldn’t register the hot key.");
            }
            catch (Exception ex)
            {
                TraceOps.Out(System.Environment.NewLine + "Target  :  " + ex.TargetSite.ToString() + System.Environment.NewLine + "Message :  " + ex.Message.ToString() + System.Environment.NewLine + "Stack   :  " + ex.StackTrace.ToString());
            }
        }