Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / What to do with button_id_to_char / char_to_button_id?
- By jlnr (dev) Date 2009-05-23 18:08
Quick poll because I'm thinking about what I should change in Gosu 0.8:

These two functions (button_id_to_char/char_to_button_id) have always been hard to implement across operating systems, and I am thinking about dropping them altogether. Does anyone have a real use for them? For entering text, TextInput is the way to go anyway, but maybe I'm missing other uses of them.

The way I see it, button_id_to_char is only useful to present the controls of the game to the user. If a game uses KbW, KbA, KbS, KbD as the controls, button_id_to_char() will always return the actual characters on these keys on different international keyboards. But then, shouldn't it just be name_of_button?
My use case would be that the user has to press the button they want to use for walking, firing, whatever, and the game would use this function to determine the name. Which leads to the question, should it also return names for keys such as 'left arrow' and 'backspace' (seems like a pretty common need to me)? If so, should these names be localized? I think only Windows has a function to get the localized name of a key. Should Gosu just include as many localizations as possible for other systems?

Any feedback welcome :)
- By benko Date 2009-05-23 20:03
I think there should be a function to get some kind of identifier (the scancode could do the job, I think) of the key pressed by the user. For example, if we want to include customizable controls in the game (to let the player choose which key/button wants to use to do some action). Maybe this could be done (getting the key pressed) with TextInput but maybe could cause troubles with compounds characters like é or ü or something like that.
- By Basic Date 2009-05-23 20:11
I've always wondered what use they had.
- By philomory Date 2009-05-24 01:50
Interestingly, I'm currently using the following code to get the names of keys, precisely because button_id_to_char() does not function for non-alphanumerics:

#helper hash to get Gosu button constant names
module OperationLambda
  GosuButtonIdNames = {}
 
  module_function
  def build_hash_of_gosu_button_id_names
    (Gosu.constants - ['MsNum',:MsNum]).each do |str|
      x = Gosu.const_get(str)
      if x.is_a? Fixnum
        GosuButtonIdNames[x] = str
      end
    end
  end
end

On the flip side, I actually *am* using char_to_button_id() at the moment, since there's no Gosu::KbLeftBracket and Gosu::KbRightBracket constants (that is, '[' and ']').
- By jlnr (dev) Date 2009-05-24 10:32 Edited 2009-05-24 11:41
There are no codes for [] because they are in different places on different international keyboards. I try to only encode the 'standard' keys that everyone hopefully has, like Alt and Strg. Of course, you could argue that like KbZ and the other constants, they should just always stand for "the keys next to return". Hmm. :)
Up Topic Gosu / Gosu Exchange / What to do with button_id_to_char / char_to_button_id?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill