Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Trading Journey
by 7th_zorro. 04/27/24 04:42
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 747 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Keybinds #460996
07/22/16 13:13
07/22/16 13:13
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Does anyone know a good approach for implementing keybinds?

I already have an idea but there's probably a much better solution.


POTATO-MAN saves the day! - Random
Re: Keybinds [Re: Kartoffel] #460997
07/22/16 13:25
07/22/16 13:25
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Lookup table if you want to poll, lookup table with function pointers if you want to have callbacks.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Keybinds [Re: Kartoffel] #460998
07/22/16 13:28
07/22/16 13:28

M
Malice
Unregistered
Malice
Unregistered
M



^-- Or that --- Yes definitely THAT!

Str_for_key to ->>TEXT
key_for_str return ->> scancode to array[max_key-in_order]

Key_hit / key_pressed / key_lastpressed /key_any combinations for the rest.

Last edited by Malice; 07/22/16 13:29.
Re: Keybinds [Re: WretchedSid] #460999
07/22/16 13:37
07/22/16 13:37
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
@JustSid:
So you mean I create an array of bytes/ints (whichever I need) where each element represents one key of the keyboard (keycode = index) to store an id to what that keyshould do? Sounds good

I thought about it the other way around. Storing the corresponding keycode for each action (jump, walk left, walk right, etc.) and scanning that key everytime the action is needed (or scanning the keys for all actions at the start of each frame and storing the results using a struct).

Edit: I just have to think about how to do this in acknex... afaik there's no function that takes a keycode and returs whether or not this key is pressed.

Edit2: I'll probably go for the windows api and do that stuff myself. Not sure about gamepad input, though.

Last edited by Kartoffel; 07/22/16 13:48.

POTATO-MAN saves the day! - Random
Re: Keybinds [Re: Kartoffel] #461000
07/22/16 13:47
07/22/16 13:47

M
Malice
Unregistered
Malice
Unregistered
M



Key_hit from keys.c

opps maybe keycode and scancode are different.. Sorry, I'm in over my head and up too many hours awake.

Last edited by Malice; 07/22/16 13:49.
Re: Keybinds [Re: ] #461001
07/22/16 13:53
07/22/16 13:53
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
@Malice: cool thanks! didn't know about that one (let's hope it actually includes at least most keyboard buttons or otherwise.. winapi)

Edit: google just told me most keyboards have ~104 keys and since acknex is using an array with 256 indices for keypresses it really includes all of them I guess.

keycode, scancode...
Well, I meant the same thing as you. But no idea if there's an actual difference between those two lol

Last edited by Kartoffel; 07/22/16 13:57.

POTATO-MAN saves the day! - Random
Re: Keybinds [Re: Kartoffel] #461006
07/22/16 15:15
07/22/16 15:15
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Actually I meant that you have a table with an entry for every action that a key can be bound to and then the keycode for the key that is bound to that action. Then you can just poll the corresponding entry if/when needed.

Key binding itself is then as simple as:
Wait for any input
Update the slot in the lookup table

And tada, your keybinding has O(1) lookup time.

Something like this (pseudo-pseudo code):
Code:
enum Action
{
   WalkForward,
   Jump,

   __Max
}

KeyCodeType LookupTable[Action::__Max] = { 0 };

void BindKeyToAction(Action action)
{
   KeyCodeType input = GetNextKeyPress();
   LookupTable[action] = input;
}

void GameLoop()
{
   while(1)
   {
      if(HasInput(LookupTable[Action::Jump])
         Jump();
   }
}


Last edited by WretchedSid; 07/22/16 15:19.

Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Keybinds [Re: WretchedSid] #461009
07/22/16 16:59
07/22/16 16:59
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
@JustSid: oh okay, so it's pretty close to what I had in mind at first. However, I think I'll do the polling once every frame for all actions, store the data in a struct and pass it to the game Logic function(s).

Thank you two again for your help.


POTATO-MAN saves the day! - Random
Re: Keybinds [Re: WretchedSid] #461010
07/22/16 17:09
07/22/16 17:09
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Are not events on_a, on_b, etc key binds already? Do I missundestood something?

Re: Keybinds [Re: txesmi] #461011
07/22/16 17:31
07/22/16 17:31
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Originally Posted By: txesmi
Are not events on_a, on_b, etc key binds already? Do I missundestood something?
, I think he means customizable keybindings for e.g. player controls (like e.g. default would be WASD for movement but than an user could change it to the arrow keys).

I personally use this method now (super easy to setup and seems to work great): http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=188074
However it does not support the mouse(!). But some extra sliders and buttons for some presets could sort of fix that (I think grin ).

Page 1 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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