Key codes[solved.. sort of]
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Key codes[solved.. sort of]
I know I can go here http://irrlicht.sourceforge.net/docu/na ... .html#a183 and see the key codes, but I can't see which number is associated with them (such as w is 87 or something).
Anyone know how to do this?
Anyone know how to do this?
Last edited by monkeycracks on Sun Oct 07, 2007 9:26 am, edited 1 time in total.
right, the first (upper) key code is 0, the 2nd is 1, 3rd is 2, and so on...
but you can easily get the code with (for example):but I also don't see for what it's neccessary !?!?!
but you can easily get the code with (for example):
Code: Select all
printf("%d\n", KEY_KEY_A);
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
You shouldn't need to know the number that is associated with the enum. Everywhere you would use the number you should use the enum instead. That is why enums exist- to give a unique name to an integer value.
Maybe you could provide a simple testcase to illustrate why you would want to use or know the actual numeric value that one of the enums represents?
Travis
Maybe you could provide a simple testcase to illustrate why you would want to use or know the actual numeric value that one of the enums represents?
Travis
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
if (!strcmp(tag, "KMFo"))toload->keyMap[0].KeyCode = (EKEY_CODE)atoi(line);
if the prefix is KMFo, it'll load the integer after it and set the keycode to that integer (that stands for Keymap Move Forward)
I do this for strafe left, strafe right, move forward, and move backward
It works to just find the key doing printf(key), but I'm trying to print each key and its code to a file so I can use it for reference
if the prefix is KMFo, it'll load the integer after it and set the keycode to that integer (that stands for Keymap Move Forward)
I do this for strafe left, strafe right, move forward, and move backward
It works to just find the key doing printf(key), but I'm trying to print each key and its code to a file so I can use it for reference
-
- Posts: 58
- Joined: Thu Apr 06, 2006 11:54 pm
Can't you cast it to an int? My input handling stuff uses integers instead of Irrlicht key codes. Whenever I need to use a keycode for anything, I cast it to an int (or rather, I'm passing the keycode to a method as an int parameter). Because I always convert them to integers before using them, I never need to convert them back to Irrlicht key codes. And so, my crappy input handler becomes slightly less dependent on the graphics engine!
=D
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
- Posts: 58
- Joined: Thu Apr 06, 2006 11:54 pm
Ah, so you're just trying to write out a text file that contains a list of all the key codes, and the number for each? There probably isn't a way to turn the name of the key (for example "KEY_KEY_W") into a string.
But if I wanted a list of all the key codes with their numerical values, I'd look in Irrlicht's source where the key codes are declared. Copy and paste the list into a text file. If you've got time on your hands, you can type in the number for each yourself... but to automate it, just read that text file, and spit out another one with line numbers.
Again, I'm curious why you'd need to know the numerical values associated with the keys, please tell!
If you're trying to print out the names of the keys in your game, here's the solution I'm using:
Every key (and mouse button) is an instance of the InputKey class, which contains both the Irrlicht key code, and the name of the key. At the start of the program, all the keys need to be initialized:
createKey( irr::KEY_LBUTTON, "Left Click" );
createKey( irr::KEY_RBUTTON, "Right Click" );
createKey( irr::KEY_MBUTTON, "Middle Click" );
createKey( irr::KEY_RETURN, "Enter" );
createKey( irr::KEY_TAB, "Tab" );
etc.
Now when I want to make a GUI for customizing the keys, all the keys have nice names! I'm a big fan of OO, I'm trying to hide Irrlicht's input handling stuff as much as possible (without losing any speed).
But if I wanted a list of all the key codes with their numerical values, I'd look in Irrlicht's source where the key codes are declared. Copy and paste the list into a text file. If you've got time on your hands, you can type in the number for each yourself... but to automate it, just read that text file, and spit out another one with line numbers.
Again, I'm curious why you'd need to know the numerical values associated with the keys, please tell!
If you're trying to print out the names of the keys in your game, here's the solution I'm using:
Every key (and mouse button) is an instance of the InputKey class, which contains both the Irrlicht key code, and the name of the key. At the start of the program, all the keys need to be initialized:
createKey( irr::KEY_LBUTTON, "Left Click" );
createKey( irr::KEY_RBUTTON, "Right Click" );
createKey( irr::KEY_MBUTTON, "Middle Click" );
createKey( irr::KEY_RETURN, "Enter" );
createKey( irr::KEY_TAB, "Tab" );
etc.
Now when I want to make a GUI for customizing the keys, all the keys have nice names! I'm a big fan of OO, I'm trying to hide Irrlicht's input handling stuff as much as possible (without losing any speed).
=D
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Umm the first key starts with 1! Not 0!
If you need proof. Here are all the keycodes http://irrlicht.sourceforge.net/docu/_k ... ource.html
If you need proof. Here are all the keycodes http://irrlicht.sourceforge.net/docu/_k ... ource.html
TheQuestion = 2B || !2B
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Maybe it's starting from zero...
Anyway, i really think that when you use a lib like Irrlicht, you have to make abstraction of its implementation. If tomorrow, the Irrlicht's team decide to start key codes from 1256, you'll have to change your code too. That's why you should use key_code, without trying to know which integer is associated to them.
In addition, i think the file that contains your keymap is not supposed to be manually editing by the user, so you can simply cast the key code into an integer, what would be a lot easier
Anyway, i really think that when you use a lib like Irrlicht, you have to make abstraction of its implementation. If tomorrow, the Irrlicht's team decide to start key codes from 1256, you'll have to change your code too. That's why you should use key_code, without trying to know which integer is associated to them.
In addition, i think the file that contains your keymap is not supposed to be manually editing by the user, so you can simply cast the key code into an integer, what would be a lot easier
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
They would never happen. For the simple fact the class contains the value of the keys mapped on the keyboard. Which means if you change the value, then you change the key. There really is no need to use the abstraction enum for keys beside the fact that it makes code more readable.Perceval wrote:Maybe it's starting from zero...
Anyway, i really think that when you use a lib like Irrlicht, you have to make abstraction of its implementation. If tomorrow, the Irrlicht's team decide to start key codes from 1256, you'll have to change your code too. That's why you should use key_code, without trying to know which integer is associated to them.
In addition, i think the file that contains your keymap is not supposed to be manually editing by the user, so you can simply cast the key code into an integer, what would be a lot easier
TheQuestion = 2B || !2B