Page 1 of 1

Rubygame get_key_state

PostPosted: Sat Jul 24, 2010 12:37 am
by tyler
A while back I realized I was in need of SDL's GetKeyState. I couldn't find an equivalent in Rubygame, so I used the one in ruby-sdl-ffi, but the code I created was pretty awful. Today I fixed the awfulness, and created a proper Rubygame get_key_state method:

Code: Select all
def get_key_state
   hash = {}
   key_state = SDL.GetKeyState
   key_state.length.times do |i|
      state = (key_state[i] != 0)
      hash[Rubygame::Events._convert_key_symbol(i)] = state
   end
   hash.delete :unknown_key
   return hash
end


It returns a hash of all the key states, so one could do something like:

Code: Select all
get_key_state[:a] #=> true, if a is pressed


I humbly request that this be included in rubygame, if it's not too much of a hassle for you jacius, since I believe others could find this useful. I'd provide a patchfile or git repo to pull from, but I wasn't completely sure which part of Rubygame this would fit into.

Re: Rubygame get_key_state

PostPosted: Sun Sep 05, 2010 8:48 pm
by tyler
So... Does silence mean no?

Re: Rubygame get_key_state

PostPosted: Mon Sep 06, 2010 6:07 pm
by blue-wiz
I reckon that it's great. Maybe it should go into the global Rubygame module.
Code: Select all
Rubygame::get_key_state


Just pester jacius on IRC or email to get it into the source code :lol:

Re: Rubygame get_key_state

PostPosted: Mon Sep 06, 2010 11:37 pm
by tyler
blue-wiz wrote:I reckon that it's great. Maybe it should go into the global Rubygame module.
Code: Select all
Rubygame::get_key_state


Just pester jacius on IRC or email to get it into the source code :lol:


:P yeah, I might have to! And the main Rubygame module does seem like the best place to put it. I think I'll throw it in there and send jacius a pull request, maybe he'll see that.