相对于其他的子系统来说, 输入系统是比较简单的. 很多游戏根本就没有对这一块进行封装, 而直接采用了Win32的消息机制.

不过经过封装的输入系统使用起来很方便, 呵呵.

N3中有三种输入设备, 键盘, 鼠标, 手柄. 分别是基于Win32消息, DirectInput, XInput实现的. 这里有一个继承图能够很好的说明输入系统的组织结构:

基本的消息处理机制是这样的一个流程:

InputServer里有默认的一个键盘, 一个鼠标, 一个手柄的"handler", 在每帧开始时InputServer会检测当前的输入消息,  得到一个InputEvent, 由相应的InputHandler来处理.  各个InputHandler都保存着当前帧各种输入状态的缓存(如鼠标左键是否按下), 因此, 在程序运行过程中, 我们只要在绘制结束前检测各个InputHandler的状态就相当于知道当前用户是怎样输入的了.

一般只需要关心这么几个函数就够了:

  1. // Mouse
  2. /// return true if button is currently pressed
  3. bool ButtonPressed(Input::MouseButton::Code btn) const;
  4. /// return true if button was down at least once in current frame
  5. bool ButtonDown(Input::MouseButton::Code btn) const;
  6. /// return true if button was up at least once in current frame
  7. bool ButtonUp(Input::MouseButton::Code btn) const;
  8. /// return true if a button has been double clicked
  9. bool ButtonDoubleClicked(Input::MouseButton::Code btn) const;
  10. /// return true if mouse wheel rotated forward
  11. bool WheelForward() const;
  12. /// return true if mouse wheel rotated backward
  13. bool WheelBackward() const;
  14. /// get current absolute mouse position (in pixels)
  15. const Math::float2& GetPixelPosition() const;
  16. /// get current screen space mouse position (0.0 .. 1.0)
  17. const Math::float2& GetScreenPosition() const;
  18. /// get mouse movement
  19. const Math::float2& GetMovement() const;
  1. //Keyboard//
  2. /// return true if a key is currently pressed
  3. bool KeyPressed(Input::Key::Code keyCode) const;
  4. /// return true if key was down at least once in current frame
  5. bool KeyDown(Input::Key::Code keyCode) const;
  6. /// return true if key was up at least once in current frame
  7. bool KeyUp(Input::Key::Code keyCode) const;
  8. /// get character input in current frame
  9. const Util::String& GetCharInput() const;

GamePad先略过, 原理相同

测试例子, 在上一次的代码中添加一段:

  1. void OnRenderFrame()
  2. {
  3. if (this->inputServer->GetDefaultMouse()->ButtonDown(MouseButton::LeftButton))
  4. {
  5. MessageBoxA(this->displayDevice->GetHwnd(), "Left Button Down", NULL, 0);
  6. }
  7. //...//
  8. }

效果:

转载于:https://www.cnblogs.com/flying_bat/archive/2008/12/14/1354934.html

Nebula3的Input系统相关推荐

  1. 【Android】带你细看Android input系统中ANR的机制

    "本文基于Android13源码,分析Input系统的Anr实现原理" 在文章之前,先提几个问题: 如果在activity任意周期(onCreate,onResume等),同步执行 ...

  2. Android input 系统InputReader,InputDispatcher线程实例--UI死掉

    Android input 系统InputReader,InputDispatcher线程实例–UI死掉但touch 正常报点 依据 Android input 系统初始化和启动流程中的背景: 做An ...

  3. linux input系统的分析笔记(一)

    linux input系统的分析笔记(一) 我的学习的思路是:知其然,然后再 知其所以然. 我要得是看得到的结果和现象,然后再想办法改变和理解它的原理. 在android的shell下有个好用的工具: ...

  4. Linux/Android——Input系统之frameworks层InputManagerService (六)【转】

    本文转载自:http://blog.csdn.net/u013491946/article/details/72638954 版权声明:免责声明: 本人在此发文(包括但不限于汉字.拼音.拉丁字母)均为 ...

  5. android bsp学习_Android BSP成长计划随笔之虚拟设备搭建和input系统

    由于工作关系,对Android关注将从FWK(Framework)转向BSP,也就是Linux Kernel.在工作的5年中,曾经数次研究过kernel,但一直没有合适的机会或者说推动力去深入研究.这 ...

  6. Android 4.0 事件输入(Event Input)系统

    1. TouchScreen功能在Android4.0下不工作 原来在Android2.3.5下能正常工作的TouchScreen功能,移植到Android 4.0就不能正常工作了.凭直觉,Andro ...

  7. Android Input系统之触摸屏

    2019独角兽企业重金招聘Python工程师标准>>> 最近开始在TI平台调试触摸屏,之前研究过Android的Event输入设备驱动,对键盘比较了解.Input驱动程序包含游戏杆. ...

  8. Input系统学习-----move事件的合并

    在onTouchEvent里打印log跟踪ACTION_DOWN事件和ACTION_MOVE事件的堆栈,会发现不一样,这里直接说一下结论,在应用端接收到touch事件的时候,会对move事件会进行合并 ...

  9. [Android Input系统]MotionEvent的序列化传送

    这里从云游戏的触控操作看起, PC端的客户端支持按键和鼠标滑动操作,手机上的云游戏客户端则是和手机游戏一样的touch触控,客户端的touch操作是怎样处理给服务端的呢,猜测是把touch操作&quo ...

最新文章

  1. 使用WINAPI获得磁盘空间信息
  2. android短信功能裁剪,Android短信发送功能实现技巧分享
  3. 在studio中使用libsdl2.so,编译SDL Demo
  4. 抖音推荐机制与算法探讨
  5. 城市问题(Floyd)
  6. C#执行cmd [转载]
  7. 条件编译指令:#if,#endif
  8. 十分钟学习python_Python学习笔记一:十分钟入门
  9. access用扫描枪输入_工业级高精度扫描枪适用在哪些环境
  10. C++ 的异常处理解答
  11. windows7配置java环境变量
  12. 基于 Verilog 的经典数字电路设计(8)计数器
  13. Linux笔记:文件共享服务Samba基础使用
  14. 网站代码sql注入攻击漏洞修复加固防护措施
  15. IDEA2022 提示:更新 TKK 失败,请检查网络连接
  16. 小米pro 笔记本 计算机,【MI/小米笔记本 Pro超极本】MI 小米 笔记本 Pro 15.6英寸 笔记本电脑【报价 价格 评测 怎么样】 -什么值得买...
  17. GSMA SGP.21协议学习
  18. 币小秘:币圈五度春秋几度忧愁?解读每位投资者心态
  19. 可以让男人看一遍哭一遍的文章(转贴)
  20. homebrew 下载软件包失败,使用手动下载

热门文章

  1. nib、xib、storyboard(故事板)
  2. 谷歌Android运用商铺下架染辣手机软件
  3. 网友收集了三年的最好的设计网站
  4. REPAIR修复mysql报错is marked as crashed and should be
  5. 建设私有云需要注意哪些问题?
  6. 数据结构第二章线性表学习笔记
  7. 教你清楚了解JAVA动态代理
  8. Redis进阶实践之二如何在Linux系统上安装安装Redis
  9. Android 接入支付宝支付实现
  10. LinQ中Skip()方法和Take()方法的使用