GLBasic forum

Main forum => GLBasic - en => Topic started by: Sev on 2013-Aug-26

Title: What key is enter?
Post by: Sev on 2013-Aug-26
Hello, another question.

What key is "enter" in GLBasic?   Spacebar is key 57. e.g.-> IF KEY(57)

Thanks
Title: Re: What key is enter?
Post by: kanonet on 2013-Aug-26
Enter (or return) has the scan code number 28. At least the normal one, the enter key on the numpad has the number 156.

You can use the keycode tool to get all scan codes you want, just go to tool->keycodes or simply press alt+k.
Title: Re: What key is enter?
Post by: mentalthink on 2013-Aug-26
Sev in the help F1 you have all the relationships for the keys for all platforms...

You can use Scankey, but in the forum a Coleague did a library for the keys, my counsil it's use some variable better then only the number in example.

Code (glbasic) Select

static key_Space
key_Space=key(57)

if key_Space Do_Something 

//This Way it's better when you use a lot of keys in your code, can be difficult rebember all the keys you are using in your program...
Title: Re: What key is enter?
Post by: Schranz0r on 2013-Aug-26
Code (glbasic) Select
STATIC Key_Space = 57

IF KEY(Key_Space) THEN PRINT "WOHOO", 10,10
Title: Re: What key is enter?
Post by: spacefractal on 2013-Aug-26
for games, dont use "hardwired" keys. Uses with variable (as Schranz0r shown), so users can remap eventuelly later.

A typical "bug" is when the Z key is used for jump, but then German users cant uses that (due Z and Y are swapped)...

Here is the code im often uses to find keys (such as space, shift, pause etc):
Code (glbasic) Select


// inkey key
LOCAL INKEYED=-1

IF INKEYED=-1
IF INKEY=0
FOR i=1 TO 255
IF KEY(i)
INKEY=i
BREAK
ENDIF
NEXT
ELSE
LOCAL ok=0
FOR i=1 TO 255
ok=ok+KEY(i)
IF ok>0 THEN BREAK
NEXT
IF ok=0 THEN INKEY=0
ENDIF
ELSE
INKEY=INKEYED
ENDIF
Title: Re: What key is enter?
Post by: Schranz0r on 2013-Aug-26
nice little code :)