Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,618 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
inchar in one frame #409183
10/13/12 11:47
10/13/12 11:47
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Hi,
I wanted to ask if anyone has a solution for my following problem. I need a function that checks which key is pressed the current frame. However i want that the keys are also evaluated(f.i. shift + a = A or altgr+2 = @)
inchar would be the perfect solution, but I need a function that is executed in one frame. inchar waits until a key is pressed. I need a function that only checks if a key is pressed...
It's a bit difficult to explain... I hope you understand

regards Alain

Re: inchar in one frame [Re: krial057] #409187
10/13/12 14:09
10/13/12 14:09
Joined: Sep 2009
Posts: 1,032
Budapest
Aku_Aku Offline
Serious User
Aku_Aku  Offline
Serious User

Joined: Sep 2009
Posts: 1,032
Budapest
3DGS key_pressed function
At the bottom of the page of the Manual you can see the "See also" references. Those are also worth a peek.

Re: inchar in one frame [Re: krial057] #409188
10/13/12 14:13
10/13/12 14:13
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
That should be your solution:

http://www.conitec.net/beta/akey_lastpressed.htm

You can scan for the modifier keys with key_shift, key_control etc. The only drawback is that you will "loose" a key when the user hits two keys within one frame. That shouldn't be to likely though.

If that solution is not precise enough you can assign a function to this http://www.conitec.net/beta/aon_anykey.htm event. The scancode of the key pressed will be passed as the first argument to the function. This way you're fully independent what to do with your input and can buffer it as you see may fit your needs.

Last edited by Uhrwerk; 10/13/12 14:14. Reason: Ninjad by AkuAku :-/

Always learn from history, to be sure you make the same mistakes again...
Re: inchar in one frame [Re: Uhrwerk] #409191
10/13/12 14:32
10/13/12 14:32
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
@Aku_Aku and Uhrwerk
ty. I already know about these functions. However i would then need to scan the modifier keys and write my own mapping(and that wouldn't be the best, because i don't know which keyboard language the user has) for every key that needs a modifier... My problem is that i'm writing a textbox control. everythinng works fine. Except for the keys that need modifiers. At the moment i'm doing everything with key_pressed:
if key_pressed("2") text.append(str_for_key(indexof "2")). of course i haven't done it exactly like this, but just for the main idea. Then, "2" is added to the textbox. However, the user may have hold down the altgr key and then it shouldn't append a "2" but an "@". Of course I could write a ffuncction that checks if altgr is hold down and then make an @ out of the 2... However the at is only on some keyboards on the same place as the 2. On others it is on the q key or somewhre else.
inchar always recognizes it corretly and it is exactly that behaviour that i need...

Re: inchar in one frame [Re: krial057] #409192
10/13/12 14:37
10/13/12 14:37
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Then write a function that running in the background uses inchar and puts the keys read into a buffer. From the buffer you can then read the keys without using a wait and work with them as you like.


Always learn from history, to be sure you make the same mistakes again...
Re: inchar in one frame [Re: Uhrwerk] #409195
10/13/12 16:18
10/13/12 16:18
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Omg, i'm such an id*ot tongue of course. Thank you laugh There will soon be a screenshot on the "What are you working on? " thread of why i needed it wink

Thank you laugh

Re: inchar in one frame [Re: krial057] #409321
10/15/12 16:12
10/15/12 16:12
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Sorry for doublepost, but i still have a problem. I want to be able to still get the correct key events when inchar is activated. I have functions like:
function isKeyWDown(){return key_pressed(w);}
but when inchar is active, key_pressed only returns true on the keydownpressed event and not all the time when a key is down...

EDIT:
Here is an example to clearify:
Code:
#include <acknex.h>
STRING* lastkey = "";

void getLastKey()
{
	while(1)
	{
		inchar(lastkey);
		wait(1);
	}
}

function main()
{
	level_load(NULL);
	//getLastKey();
	while(1)
	{
		if(key_pressed(key_for_str("a")))
			draw_text("a is pressed", 10, 10, COLOR_RED);
		wait(1);
	}
}


just comment getLastKey() out to see the difference...

Last edited by krial057; 10/15/12 18:39.

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

Gamestudio download | 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