/// <summary> /// 监听键盘按键 /// </summary> public void ListenKeyEvent() { /* 当有按键按下的时候进入判断 */ if (input.CurrentState.GetPressedKeys().Length > 0) { /* 遍历所有按下的键 */ for (int i = 0; i < input.CurrentState.GetPressedKeys().Length; i++) { /* 获取当前按键 */ Keys thisKey = input.CurrentState.GetPressedKeys()[i]; Object obj = table[thisKey]; if (obj == null) { continue; } string classpath = obj.ToString(); if (classpath == null || "".Equals(classpath)) { continue; } /* 通过反射获得对应的按键处理类 */ Assembly asm = Assembly.GetExecutingAssembly(); Type t = asm.GetType(classpath); if (t == null) { continue; } Object obj1 = Activator.CreateInstance(t); /* 执行处理类 */ IInputHandler handler = obj1 as IInputHandler; if (handler == null) { continue; } handler.setController(this); handler.setKey(thisKey); handler.HandlerInput(input); } } }