Key Mapping?

Posted By: Nicholas

Key Mapping? - 06/21/11 22:32

I am sure this has been done before, but I am looking for a refresher since I can't find any mention of it.
I am looking for a way to remap my keys with as little code as possible.
What's the best way to remap my keys/joystick buttons?
I was thinking of using strings so I could do something like:

STRING* jump = "joy_1";

if (jump ==1){player_jump;}

this would obviously try to use joy_1 as the jump button, but since I don't think I can use a string in an if statement I'm not sure of the best way to do it.
I would use a panel or ini file to remap the keys as need be, but don't want to have hundreds of if then statements inside of each other for each possible combination.
Any help would be great

thanks
Posted By: painkiller

Re: Key Mapping? - 06/21/11 22:50

you can't do that, try this:

Code:
#define jump joy_1

....

if (jump ==1){player_jump;}


Posted By: lostclimate

Re: Key Mapping? - 06/22/11 04:49

look up key_set in the manual.
Posted By: Redeemer

Re: Key Mapping? - 06/22/11 15:25

Key_set will not help, as it is used to map on_key functions, and neither will a #define statement, as that doesn't even allow you to remap keys in game.

What you need to use is the key_for_str() and str_for_key() functions, but those only work for keyboard input. For mouse and joystick input, search for my functions on the forums: input_for_str() and str_for_input(). They work exactly the same as key_for_str() and str_for_key(), but they also accept mouse and joystick scan codes.
Posted By: Helghast

Re: Key Mapping? - 06/22/11 15:27

I included a template file for this in my RPG Template that you can take out of AUM100. Reads custom key setup from a .ini file laugh
Posted By: Nicholas

Re: Key Mapping? - 06/22/11 16:23

I've been meaning to take a look at AUM100, nice setup there with the search functions and all the downloads.
I think I got it to work with keyboard and joysticks with as little code as possible. I needed to make it know if the button was held down so remapping the key to the function didn't seem to work too well, so I used a while loop in an action and just used the function part to set a var to the key pressed

var duck_v;
var jump_v;

function duck_f() {duck_v = key_lastpressed; } //set duck var
//joy_1 = 256, a = 30, etc
function jump_f() {jump_v = key_lastpressed; } //set jump var

//use this part for the mapping:

while (key_any == 0) { wait(1); } // wait until a key is hit
key_set(key_lastpressed,duck_f); // assign function to key
while (key_any == 1) { wait(1); } // wait until key is released
while (key_any == 0) { wait(1); } // wait until a key is hit
key_set(key_lastpressed,jump_f); // assign function to key


//put the rest in a while loop somewhere"

if (key_pressed(jump_v) == 1){//jump anim/etc
if (key_pressed(duck_v) == 1){//duck animation/action/sound etc...

will also know if key is held down and since key_pressed works with the 256+ numbers not just the lower ones it'll work with joysticks too.


There might be a more correct way, but this seems to work for me. I'll still take a look at the aum and see if there is anything that'll work for my application in there
Posted By: JimFox

Re: Key Mapping? - 06/22/11 18:39

I don't see AUM100 at the magazine site.
Am I missing something?
Posted By: 3run

Re: Key Mapping? - 06/22/11 18:42

I guess yes? Cause I see it without any problems. About key mapping, see shooter templates.
Posted By: Helghast

Re: Key Mapping? - 06/23/11 09:44

There is also custom key mapping in the Super Menu that I did a while ago for TerraSame. Works similar to what you posted above laugh
© 2024 lite-C Forums