private void setCurrentKeyStatus(Keys keyCode, KeysState currentKeyState) { if (keysStatusTable.Contains(keyCode)) { keysStatusTable[keyCode] = currentKeyState; } else { //erorr: this key is not registed(出力 } }
public KeysState getCurrentKeyStatus(Keys keyCode) { KeysState currentKeyStatus = KeysState.NotRegisted; if (keysStatusTable.Contains(keyCode)) { currentKeyStatus = (KeysState)keysStatusTable[keyCode]; } return(currentKeyStatus); }
// Action é uma referência a uma função void f(void) public static void Register(Keys key, KeysState state, Action code) { // Do we have this key already in the dictionary? if (!_instance._actions.ContainsKey(key)) { _instance._actions[key] = new Dictionary <KeysState, List <Action> >(); } // For this key, do we have that state created? if (!_instance._actions[key].ContainsKey(state)) { _instance._actions[key][state] = new List <Action>(); } // Add the code to the key/state pair _instance._actions[key][state].Add(code); // Add the key to the keyboard state dictionary _instance._keyboardState[key] = KeysState.Up; }
public KeyBoardHookEventArgs(Keys key, KeysState keystate) { _key = key; _keyState = keystate; }
public override void Update(GameTime gameTime) { KeyboardState state = Keyboard.GetState(); List <Keys> pressedKeys = state.GetPressedKeys().ToList(); // Process pressed keys foreach (Keys key in pressedKeys) { // If we didn't know anything about this key, then probably it was up. if (!_keyboardState.ContainsKey(key)) { _keyboardState[key] = KeysState.Up; } // What was the previous state, and decide what is our next state switch (_keyboardState[key]) { /* Estado Anterior Agora Guardo * DOWN DOWN Down * GOING DOWN DOWN Down * UP DOWN Going Down * GOING UP DOWN Going Down */ case KeysState.Down: case KeysState.GoingDown: _keyboardState[key] = KeysState.Down; break; case KeysState.Up: case KeysState.GoingUp: _keyboardState[key] = KeysState.GoingDown; break; } } // Processed released keys // Keys[] x = _keyboardState.Keys.Except(pressedKeys).ToArray(); // foreach (Keys key in x) // same as... foreach (Keys key in _keyboardState.Keys.Except(pressedKeys).ToArray()) { /* Estado Anterior Agora Guardo * DOWN UP GoingUp * GOING DOWN UP GoingUp * UP UP UP * GOING UP UP UP */ switch (_keyboardState[key]) { case KeysState.Down: case KeysState.GoingDown: _keyboardState[key] = KeysState.GoingUp; break; case KeysState.Up: case KeysState.GoingUp: _keyboardState[key] = KeysState.Up; break; } } // Invocar as funções registadas! foreach (Keys key in _actions.Keys) { KeysState kstate = _keyboardState[key]; if (_actions[key].ContainsKey(kstate)) { foreach (Action action in _actions[key][kstate]) { action(); } } } }
public KeyBoardHookEventArgs(Keys key,KeysState keystate) { _key=key; _keyState=keystate; }