Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: Convert String to Keycode  (Read 954 times)

rewb0rn

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Convert String to Keycode
« on: December 10, 2006, 03:53:34 AM »

Hi, I am new to OIS and I am just working on a method to load the keys from an ini file and save them after.

I use Keyboard::getAsString() to convert the Key, but is there a method to convert such a string to a Keycode? I need it when I read the String from the ini file. Do I have to implement it on my own? I hope not^^

Btw: When I registered, it said my email adress @web.de is banned, allthough Ive never been here before.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Convert String to Keycode
« Reply #1 on: December 10, 2006, 08:29:04 AM »

Sorry about the website. I will unblock that email (it isn't your email, but a wild card *web.de) - it was used by many many spammers. However, I installed a new spam filter that has reduced many spam registers.

As for translating between key name as a string and keycode. That would be very language independent and there is no method in OIS to do that.  The main reason why not is because OIS uses OS methods to obtain the name of the string in the current language locale.

What you should do is not worry about the string name. Instead, store your key <-> action (what I assume you are trying to accomplish) in the form of keycode <-> action. I had an action map demo in OIS 0.7 and below. However, I removed it in 1.0 because I do not have time to keep the demo uptodate (using Ogre and OIS). You could download that source to see action mapping in action ;) You just need to have Ogre Dagon and CEGUI 0.4.x - you could even get the demo working with OIS 1.0 with a few changes.
Logged

rewb0rn

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Convert String to Keycode
« Reply #2 on: December 10, 2006, 09:31:48 AM »

Ok, thanks for your reply. Yes, i want to store the key <-> action. The problem is when I just save the Keycode, its not really obvious what key is used, so as long as I dont have a menu, Id always have to check what key has what value, I hoped to avoid this.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Convert String to Keycode
« Reply #3 on: December 10, 2006, 09:43:09 AM »

It should be obvious to you what keycode does what on your system. Though, if you plan to present this information to your user, then I agree that would eb a bad idea. A menu configuration screen is the best. However, if you can't do that due to lack of time/budget, you could always make your own lookup table to convert from string (any string you decide to use) to KeyCode.

Here is a script code I am currently using in my engine. Notice the numbers at the very bottom.
https://www.wreckedgames.com/svn/ringo/trunk/bin/media/nuts/InputCfg.nut
Such as:
::Ois.addEvtBinding(0, ::Ois_Keyboard, ::A_MOVE_BACKWARD, 208, ::Ois_Button, "handleMove");

I just use the number 208 instead of the key code, because I didn't feel like binding all the enum values to script :)
Logged