Page 1 of 1

remapKey() question

PostPosted: Fri May 19, 2006 5:43 am
by DilloDude
I was wondering about remapping keys for player configuration. If I had a keydown event for space, and I remapped it to enter, and then I decided to remap it to Left shift, would I have to put remapKey(KEY_RETURN, KEY_LSHIFT); or could I use remapKey(KEY_SPACE, KEY_LSHIFT);?

PostPosted: Fri May 19, 2006 3:17 pm
by makslane
remapKey(KEY_LSHIFT, KEY_SPACE);

When user press left shift, the key will be translated to the space used by your event.

PostPosted: Sat May 20, 2006 12:26 am
by DilloDude
Awesome!

PostPosted: Sat May 20, 2006 7:18 am
by DilloDude
Now I'm getting a bug. I have a setup so the player can configure the controls, but when I set them to anything other than the defaults, they don't work at all. But the code for when you click the play button is
Code: Select all
remapKey(KEY_UP, controlconfig[1]);
remapKey(KEY_LEFT, controlconfig[2]);
remapKey(KEY_LSHIFT, controlconfig[3]);
remapKey(KEY_RIGHT, controlconfig[4]);
remapKey(KEY_DOWN, controlconfig[5]);
remapKey(KEY_SPACE, controlconfig[6]);

And I have a text displaying the key text of controlconfig[1-6], and it shows the right key.

PostPosted: Sat May 20, 2006 7:47 am
by twobob
Check to make sure that your array controlconfig is of type integer.
Also check that when you load the values into controlconfig it is something like the following:

controlconfig[1] = KEY_z;
controlconfig[2] = KEY_x;
controlconfig[3] = KEY_SPACE;
controlconfig[4] = KEY_p;
controlconfig[5] = KEY_l;
controlconfig[6] = KEY_m;

Also have a look at the topic at:
http://game-editor.com/forum/viewtopic.php?t=1534&postdays=0&postorder=asc&highlight=remapkey&start=0
Which might give you some tips on doing this

PostPosted: Sat May 20, 2006 8:07 am
by DilloDude
Here's what I am doing: I have a picture with keys on it, with filled-regions over them for buttons. On a mouse button down on one of these, it sets a variable assign to a value representing the key. I have another actor 'Assigning' which has a keydown event->any key, with the following code:
Code: Select all
switch (assign)
{
    case 1:
    controlconfig[1] = getLastKey();
    break;
 
    case 2:
    controlconfig[2] = getLastKey();
    break;
 
    case 3:
    controlconfig[3] = getLastKey();
    break;
 
    case 4:
    controlconfig[4] = getLastKey();
    break;
 
    case 5:
    controlconfig[5] = getLastKey();
    break;
 
    case 6:
    controlconfig[6] = getLastKey();
    break;
}
controlconfig[0] = 1;
assign = 0;
saveVars("config.stp", "config");
controlconfig[0] is used to find if the file config.stp exists. I have a text actor displaying the text of the keys (strcpy(text, getKeyText(controlconfig[1]));) and it displays it fine. But when I click on the play button where it should remap the keys, it obviously does something, because the default keys don't work - neither do the ones I set them to. But if I set any keys back to the default keys, those ones work fine.

PostPosted: Sat May 20, 2006 8:07 am
by twobob
Just another thought, are you putting the values the right way round into remapKey?
It should be remapKey(getLastKey(), controlconfig[1]);
Where controlconfig[1] is the original key in the game

PostPosted: Sat May 20, 2006 8:16 am
by twobob
Looking at your last post, I think you might have the values in remapKey the wrong way round
Try remapKey(controlconfig[1], KEY_UP); in your script

PostPosted: Sat May 20, 2006 8:16 am
by DilloDude
That would be it. :oops: That's a thing to remeber with remapKey: get the order right. Thanks for that; I thought I checked that before, but obviously I was wrong.

PostPosted: Mon May 22, 2006 6:04 am
by DilloDude
Now my new problem:
I have it set so if the keys are not the default keys, it remaps the defaults around so they don't still work:
Code: Select all
if (controlconfig[1] != KEY_UP){remapKey(KEY_UP, KEY_LWINDOWS);}
...

But if I set a key to c, and then I set it to d, Both c and d will work. Is there a way I can fix this? Maybe have another array with the previous set keys?

PostPosted: Mon May 22, 2006 6:24 am
by Fuzzy
DilloDude wrote:But if I set a key to c, and then I set it to d, Both c and d will work. Is there a way I can fix this? Maybe have another array with the previous set keys?


I have never played with this, but can you set the current setting to null?

PostPosted: Mon May 22, 2006 6:28 am
by DilloDude
I think what I really want is a way to remap each key back to itself. Maybe a for loop that goes through the number of keys, and says
Code: Select all
remapkey(i, i);
would work. I'll try that.

PostPosted: Mon May 22, 2006 6:33 am
by Fuzzy
Use getch(num) to grab the key from a looped count.

PostPosted: Mon May 22, 2006 8:04 am
by twobob
I think I had the same problem as you, but with the pocket pc keys.
Take a look at the topic on the second page

http://game-editor.com/forum/viewtopic.php?t=1534&postdays=0&postorder=asc&highlight=remapkey&start=0
“A problem I found is when entering a new key to a key that is already remapped previously, then it can start to cause problems with the keys in the game
The solution I found is before you remap the keys, remap every key in the pocket pc to a key that is not used when running the game.
remapKey(KEY_POCKET_UP, KEY_g);
remapKey(KEY_POCKET_DOWN, KEY_g);
remapKey(KEY_POCKET_LEFT, KEY_g);
remapKey(KEY_POCKET_RIGHT, KEY_g);
remapKey(KEY_POCKET_A, KEY_g); ……………………….
Where the key g is not used in the game.
Also in the Config - game properties – I left all the keys to be remapped blank. When the game starts I use a saved file to load and remap the keys.”

I done this manually but as there are a lot of keys on the keyboard you may want to find a way to loop through these.