Forums Archived

The forums are being archived. See this topic for more information.

Rubygame get_key_state

Discussion about anything related to Rubygame

Rubygame get_key_state

Postby tyler » Sat Jul 24, 2010 12:37 am

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.
tyler
 
Posts: 25
Joined: Sat Feb 28, 2009 6:10 am

Re: Rubygame get_key_state

Postby tyler » Sun Sep 05, 2010 8:48 pm

So... Does silence mean no?
tyler
 
Posts: 25
Joined: Sat Feb 28, 2009 6:10 am

Re: Rubygame get_key_state

Postby blue-wiz » Mon Sep 06, 2010 6:07 pm

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:
blue-wiz
 
Posts: 12
Joined: Mon Jun 28, 2010 4:27 pm

Re: Rubygame get_key_state

Postby tyler » Mon Sep 06, 2010 11:37 pm

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.
tyler
 
Posts: 25
Joined: Sat Feb 28, 2009 6:10 am


Return to Rubygame (General)

Who is online

Users browsing this forum: No registered users and 1 guest

cron