Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TedMar, AndrewAMD, alibaba, 7th_zorro, 1 invisible), 1,049 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Easy keymapping #188067
03/12/08 09:06
03/12/08 09:06
Joined: Apr 2005
Posts: 3,815
Finland
Inestical Offline OP
Rabbit Developer
Inestical  Offline OP
Rabbit Developer

Joined: Apr 2005
Posts: 3,815
Finland
People nowdays need to be able to modify the key mapping, so using key_w, key_s, etc. will not be tolerated. That's why one should use strings or other method for checking which key was pressed.

No credits required, but note that this was also partially Kiyaku's idea.

For this I made this simple script:

Code:

// Key mapping
string keyForward = "w";
string keyBackward = "s";
string keyStrafeLeft = "a";
string keyStrafeRight = "d";
string keyRun = "shiftl";
string keyJump = "space";
string keyStrafe = "ctrll";

function getKey(key)
{
return (key_pressed(key_for_str(key)));
}



usage
Code:

if(getKey(keyForward))
{
//Do Stuff
}
// returns true/1/on wether button associated to forward movement is pressed



Key mapping can be found in the manual. Look for function "key_for_str" for complete list of accepted strings. AFAIK it's just key_blaa without the "key_".

Edit: This should work on mouse, but I'm not completely sure.


"Yesterday was once today's tomorrow."
Re: Easy keymapping [Re: Inestical] #188068
03/13/08 20:37
03/13/08 20:37
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
hey, nice way to do that.
I just wonder what would be the best way to save the changed keymapping in a file...and to load it

Re: Easy keymapping [Re: Scorpion] #188069
03/13/08 20:45
03/13/08 20:45
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
I always use an array and save the scan codes inside of it.
But your solution is also pretty nice, however I prefer the array because of saving/loading (just cycling through).

Re: Easy keymapping [Re: Xarthor] #188070
03/13/08 20:49
03/13/08 20:49
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
yeah that is good Xarthor...
I think the best way would be an array of strings you can acces with defines(i.e. #define keyForeward 0)
and then there is also no problem with saving and loading

Thank you guys, you solved my problem

Re: Easy keymapping [Re: Scorpion] #188071
03/14/08 12:16
03/14/08 12:16
Joined: Apr 2005
Posts: 3,815
Finland
Inestical Offline OP
Rabbit Developer
Inestical  Offline OP
Rabbit Developer

Joined: Apr 2005
Posts: 3,815
Finland
Using defines won't allow you to change the keymapping without restart (same as using key_lol), so using strings, maybe in an array, is way better. Also you can use the strings themselves for display, and not to rewrite them.

well, I use this to set the new key

Code:

function setKey()
{
return (str_for_key(key_lastpressed));
}



Usage:
Code:

...
if(forwardchange == 1)
{
keyForward = setKey();
}
...




"Yesterday was once today's tomorrow."
Re: Easy keymapping [Re: Inestical] #188072
03/14/08 14:27
03/14/08 14:27
Joined: Feb 2006
Posts: 2,185
mpdeveloper_B Offline
Expert
mpdeveloper_B  Offline
Expert

Joined: Feb 2006
Posts: 2,185
Xarthor this is pretty good, i assume this is from my post about how to do this. I didn't think of doing it this way, but the problem is that str_for_key doesn't support mouse functions it's keyboard exclusive. i will be starting on one that will support mouse and joystick all in one, but it will take some time because i have to use the key numbers and then tell it to convert it to the key name "ie 1 = esc".

thanks for the keyboard controls this would be very helpful for a puzzle game or any game that requires keyboard


- aka Manslayer101
Re: Easy keymapping [Re: mpdeveloper_B] #188073
03/14/08 16:17
03/14/08 16:17
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
@Inestical:
You are right, you could use the text array for displaying the key mapping aswell.
But (now here comes the but ) in my humble oppinion the normal/standard user might be confused by the names.
Thus I did take my time to write some kind of hugh text array ranging to the highest scan code.
It includes a name for the keys (that I can change etc.) but maintains the right order.
Thus it allows me to access this text array with the scan code of the key and I'll be able to get the string I chosed for that specific key.

just an idea

Re: Easy keymapping [Re: Xarthor] #188074
03/14/08 16:53
03/14/08 16:53
Joined: Feb 2008
Posts: 4
Nanning,Guangxi,China
harrisyu Offline
Guest
harrisyu  Offline
Guest

Joined: Feb 2008
Posts: 4
Nanning,Guangxi,China
I think using number instead of string would be nicer.
Because string comparing take times.

Here is what I though about customize control in game:

A function for returning string with given input,like:
PlayerMoveForwardKey = getContStr( theControlNumberOfInput );
That's just for displaying what input have set for a certain action;

Then we store 'theControlNumberOfInput' in a value , use this value in
the function that handling control reaction.


3D Game Studio commercial 7.07 Tools:Blender/Silo/Bryce/Photoshop/Artrage/Flash I like platform game.
Re: Easy keymapping [Re: Xarthor] #188075
03/14/08 16:58
03/14/08 16:58
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline
Serious User
Scorpion  Offline
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
here i did a quick code how i mean it. Should work, but I didn't test it:

Code:
#define keyForward 0
#define keyBackward 1
#define keyStrafeLeft 2
#define keyStrafeRight 3
#define keyRun 4
#define keyJump 5
#define keyStrafe 6

#define numberOfKeys 7

STRING* keyMappingStr[numberOfKeys];

void mappingInit()
{
int i;
int fileHandle;
fileHandle = file_open_read("keyMapping");
for(i=0;i<numberOfKeys;i++)
{
keyMappingStr[i] = file_str_read(fileHandle);
}
file_close(fileHandle);
}

int getKey(key)
{
return (key_pressed(key_for_str(keyMappingStr[key])));
}



Re: Easy keymapping [Re: Scorpion] #188076
03/14/08 18:52
03/14/08 18:52
Joined: Sep 2005
Posts: 980
Aue, Sachsen, Germany
W
Wicht Offline
User
Wicht  Offline
User
W

Joined: Sep 2005
Posts: 980
Aue, Sachsen, Germany
deleted by Wicht

Last edited by Wicht; 03/14/08 19:21.
Page 1 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1