public void GetCurrentKeyboardState() { keyState = device.GetCurrentKeyboardState(); }
private static string GetKeyString(DI.KeyboardState ks, DI.Key[] keys) { char c = '×'; string final = String.Empty; foreach (DI.Key k in keys) { // Specialty list if (k == DI.Key.D0) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += ")"; } else { final += "0"; } continue; } if (k == DI.Key.D1) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "!"; } else { final += "1"; } continue; } if (k == DI.Key.D2) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "@"; } else { final += "2"; } continue; } if (k == DI.Key.D3) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "#"; } else { final += "3"; } continue; } if (k == DI.Key.D4) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "$"; } else { final += "4"; } continue; } if (k == DI.Key.D5) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "%"; } else { final += "5"; } continue; } if (k == DI.Key.D6) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "^"; } else { final += "6"; } continue; } if (k == DI.Key.D7) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "&"; } else { final += "7"; } continue; } if (k == DI.Key.D8) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "*"; } else { final += "8"; } continue; } if (k == DI.Key.D9) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "("; } else { final += "9"; } continue; } if (k == DI.Key.Minus) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "_"; } else { final += "-"; } continue; } if (k == DI.Key.Space) { final += " "; continue; } if (k == DI.Key.BackSlash) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "|"; } else { final += "\\"; } continue; } if (k == DI.Key.Slash) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "?"; } else { final += "/"; } continue; } if (k == DI.Key.Apostrophe) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "\""; } else { final += "'"; } continue; } if (k == DI.Key.Comma) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += "<"; } else { final += ","; } continue; } if (k == DI.Key.Period) { if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += ">"; } else { final += "."; } continue; } // Letters if (Enum.GetName(typeof(DI.Key), k).Length == 1) { c = Enum.GetName(typeof(DI.Key), k)[0]; if (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]) { final += new string(c, 1).ToUpper(); } else { final += new string(c, 1).ToLower(); } } } return(final); }
public virtual void Render() { if (!Prometheus.Instance.MdxInputAquired) { return; } DI.KeyboardState ks = null; //try //{ ks = MdxInput.Keyboard.GetCurrentKeyboardState(); //} //catch (DirectXException) // most likely not acquired //{ // return; //} if (ks[DI.Key.Grave]) { if (rendering) { command = String.Empty; rendering = false; } else { rendering = true; } while (MdxInput.Keyboard.GetPressedKeys().Length > 0) { /* hack: probably shouldn't be doing this */; } } if (rendering) { if (ks[DI.Key.BackSpace]) { if (command.Length > 0) { command = command.Remove(command.Length - 1); } } command += GetKeyString(ks, MdxInput.Keyboard.GetPressedKeys()); string drawString = Prompt + command; if ((Environment.TickCount & 0x200) == 0) { drawString += Cursor; } font.DrawText(null, drawString, 16, device.Viewport.Height - 28, Color.HotPink); if (ks[DI.Key.Return]) { history.Add(command); if (history.Count > maxHistory) { history.RemoveAt(0); } Execute(); index = history.Count; command = String.Empty; rendering = false; } if (ks[DI.Key.Up]) { if (index > 0) { index--; } if (index < history.Count) { command = history[index]; } } if (ks[DI.Key.Down]) { if (index < history.Count - 1) { index++; } if (index < history.Count) { command = history[index]; } } while ((MdxInput.Keyboard.GetPressedKeys().Length > 0 && !ks[DI.Key.LeftShift] && !ks[DI.Key.RightShift]) || (MdxInput.Keyboard.GetPressedKeys().Length > 1 && (ks[DI.Key.LeftShift] || ks[DI.Key.RightShift]))) { /* hack: probably shouldn't be doing this */; } } RenderCore.EnableCameraInput = !rendering; }
internal KeyboardStateWrapper(Microsoft.DirectX.DirectInput.KeyboardState state) { m_state = state; }