remapKey() question

Game Editor comments and discussion.

remapKey() question

Postby DilloDude » Fri May 19, 2006 5:43 am

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);?
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby makslane » Fri May 19, 2006 3:17 pm

remapKey(KEY_LSHIFT, KEY_SPACE);

When user press left shift, the key will be translated to the space used by your event.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby DilloDude » Sat May 20, 2006 12:26 am

Awesome!
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Sat May 20, 2006 7:18 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby twobob » Sat May 20, 2006 7:47 am

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
twobob
 
Posts: 33
Joined: Sat Sep 10, 2005 10:29 am
Location: England
Score: 2 Give a positive score

Postby DilloDude » Sat May 20, 2006 8:07 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby twobob » Sat May 20, 2006 8:07 am

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
twobob
 
Posts: 33
Joined: Sat Sep 10, 2005 10:29 am
Location: England
Score: 2 Give a positive score

Postby twobob » Sat May 20, 2006 8:16 am

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
twobob
 
Posts: 33
Joined: Sat Sep 10, 2005 10:29 am
Location: England
Score: 2 Give a positive score

Postby DilloDude » Sat May 20, 2006 8:16 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Mon May 22, 2006 6:04 am

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?
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Fuzzy » Mon May 22, 2006 6:24 am

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?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby DilloDude » Mon May 22, 2006 6:28 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Fuzzy » Mon May 22, 2006 6:33 am

Use getch(num) to grab the key from a looped count.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby twobob » Mon May 22, 2006 8:04 am

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.
twobob
 
Posts: 33
Joined: Sat Sep 10, 2005 10:29 am
Location: England
Score: 2 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest