我正在使用 sdl,如何发送假键盘事件?
基本上我正在尝试使用 sdl(简单的直接媒体层)制作键盘映射器的操纵杆,
我可以毫无问题地找到我按下的操纵杆按钮。问题似乎出在伪造按键上。
Basically I am trying to make a joystick to keyboard mapper with sdl(simple directmedia layer)
I have no problem in finding which joystick button i have pressed. the problem seems to be with faking a keystroke.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为你可以“伪造”击键,但你可以声明一个布尔值数组,其中包含是否按下特定键(你可以使该数组对于每个键盘键来说足够大,然后是“A”键)例如,可以引用数组中的第 65 个元素)。
将数组的所有元素初始化为 false。然后当按下某个键时,将数组中相应的元素设置为 true,当松开键时,将其设置为 false。然后,要将操纵杆按钮映射到键盘按键,您所要做的就是在按下/释放特定操纵杆按钮时,它会更改与您想要在数组中将按钮映射到的键盘按键对应的元素之一。然后,您必须编辑代码以引用数组进行输入,而不是直接从 SDL 事件中引用。
希望这有帮助!
I don't think you can 'fake' a keystroke, but you could declare an array of boolean values that contains whether a particular key is pressed (you could make the array be large enough for every keyboard key and then the 'A' key, for example, could refer to the 65th element in the array).
Initialise all of the elements of the array to false. Then when a key is pressed, set the corresponding element in the array to true, and when it is released, set it to false. Then to map joystick buttons to keyboard keys, all you have to do is make it so when a particular joystick button is pressed/released, it changes one of the elements corresponding to the keyboard key you want to map the button to in the array. Then you'd have to edit your code to refer to the array for input rather than directly from SDL events.
Hope this helps!
使用 SDL_PushEvent。
http://www.libsdl.org/docs/html/sdlpushevent.html
Use SDL_PushEvent.
http://www.libsdl.org/docs/html/sdlpushevent.html