开发者

I am using sdl, how do i send fake keyboard events?

开发者 https://www.devze.com 2023-03-03 14:31 出处:网络
Basically I am tryin开发者_运维问答g to make a joystick to keyboard mapper with sdl(simple directmedia layer)

Basically I am tryin开发者_运维问答g 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.


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!


Use SDL_PushEvent.

http://www.libsdl.org/docs/html/sdlpushevent.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号