Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: Is it possible to make a good key binding system using OIS?  (Read 981 times)

ahnurmi

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 1
    • View Profile
Is it possible to make a good key binding system using OIS?
« on: December 07, 2007, 01:57:34 PM »

Hi,

I'm trying to do a key binding system and Do It Right, like most commercial games do. Is that currently possible with OIS?

First, I have problems creating a default key binding file. I want the console mapped to the key left of number 1. It shouldn't matter which keyboard layout the player has. I want the raw keycodes for this purpose, where no layouts have been applied. The location of the key is more important than the text on top of it. OIS doesn't even seem to have a keycode for that particular key (§) in the scandinavian layout, so I'm forced to use translated characters in key binding files. That means that I'd need a default key binding file for every keyboard layout there is. By the way, is there a reason why open source input systems always use their own keycodes?

Second, I want to show those keys on screen as text. There's a function 'getAsString', but it doesn't seem to return anything consistent when it encounters an unknown key. Usually the returned string is called 'section' for some reason. (This might be fixed in a CVS release, though?) In the case of an unknown key, I'd like to show the text 'key x', where x is the unicode character for the key, or maybe just  print an unique keycode.

I'd also like to know which platforms currently support Unicode translation, since that's quite essential especially if you can't trust that every key in a keyboard has its unique keycode.

On a side note, if you know of a clever way of doing key bindings in C++, please share it!
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Re: Is it possible to make a good key binding system using OIS?
« Reply #1 on: December 07, 2007, 05:05:55 PM »

Hi,

I'm trying to do a key binding system and Do It Right, like most commercial games do. Is that currently possible with OIS?

Of course it is. Though, I think your approach is wrong...

Quote
First, I have problems creating a default key binding file. I want the console mapped to the key left of number 1. It shouldn't matter which keyboard layout the player has. I want the raw keycodes for this purpose, where no layouts have been applied. The location of the key is more important than the text on top of it. OIS doesn't even seem to have a keycode for that particular key (§) in the scandinavian layout, so I'm forced to use translated characters in key binding files. That means that I'd need a default key binding file for every keyboard layout there is. By the way, is there a reason why open source input systems always use their own keycodes?

You shouldn't care about the location. That is the purpose of the bindings... You can let your users change them to the way they want. Alternatively, you can provide different default binding files based on locale. Binding on character is useless, scan codes are the way to go. As for your question about why does OIS (and other libs) provide keycodes... What key codes would you have? DirectX/Win32? x11? Osx?.. In fact, OIS keycodes are identical to Win32/DirectX values... The only reason they are there is to create a standard interface to users of OIS.. else, you might as well use x11, win32/directx your self.

Quote

Second, I want to show those keys on screen as text. There's a function 'getAsString', but it doesn't seem to return anything consistent when it encounters an unknown key. Usually the returned string is called 'section' for some reason. (This might be fixed in a CVS release, though?) In the case of an unknown key, I'd like to show the text 'key x', where x is the unicode character for the key, or maybe just  print an unique keycode.

I'd also like to know which platforms currently support Unicode translation, since that's quite essential especially if you can't trust that every key in a keyboard has its unique keycode.

On a side note, if you know of a clever way of doing key bindings in C++, please share it!
GetAsString uses OS API to get value, you get what you get from the OS, hard to say what it will end up as. As far as getting character values, you need to use the 'text' member of the key event in key pressed callback for that. It is mostly UTF, not quite unicode - still needs some work.

There is/was a binding demo/source included with OIS. Unfortunately, it used Ogre and CEGUI versions of an old API.. since, they change so often, I was not able to keep demo upto date.. plus Ogre now uses OIS anyway.
Logged

OvermindDL1

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 288
    • View Profile
    • http://www.overminddl1.com/forum/
Re: Is it possible to make a good key binding system using OIS?
« Reply #2 on: December 15, 2007, 10:15:33 AM »

The binding system I use is just a simple mapping using boost::channel, makes it on the order of freakishly powerful and simple while only needing to create a very small amount of code, might look into it?
Logged