Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / GetRawKeyState is case sensitive ??

Author
Message
jamesL
14
Years of Service
User Offline
Joined: 31st May 2010
Location:
Posted: 21st Nov 2014 21:24
so I just downloaded and installed AGK2 from Steam

first thing I did was try the
3D-FirstPersonExample

rem this is the original code
rem it uses the arrows keys to move
rem and works fine
rem Move camera
if GetRawKeyState(38)=1 then MoveCameraLocalZ(1,4.0)
if GetRawKeyState(40)=1 then MoveCameraLocalZ(1,-4.0)
if GetRawKeyState(37)=1 then RotateCameraGlobalY(1,-4.0)
if GetRawKeyState(39)=1 then RotateCameraGlobalY(1,4.0)

rem try lower case w, s, a, d
rem does not work
if GetRawKeyState(119) = 1 then MoveCameraLocalZ(1,4.0)
if GetRawKeyState(115) = 1 then MoveCameraLocalZ(1,-4.0)
if GetRawKeyState(97) = 1 then RotateCameraGlobalY(1,-4.0)
if GetRawKeyState(100) = 1 then RotateCameraGlobalY(1,4.0)

rem upper case
rem this works, it doesn't matter if I have caps lock on or not
rem if GetRawKeyState(87) = 1 then MoveCameraLocalZ(1,4.0)
rem if GetRawKeyState(53) = 1 then MoveCameraLocalZ(1,-4.0)
rem if GetRawKeyState(65) = 1 then RotateCameraGlobalY(1,-4.0)
rem if GetRawKeyState(68) = 1 then RotateCameraGlobalY(1,4.0)


so, what am I doing wrong ?
why does lower case not work ?
Yodaman Jer
User Banned
Posted: 21st Nov 2014 21:38
I think the reason it doesn't work that way is because they don't expect you to use both numerical representations of a letter, for example, they expect you to use "87" for "W" AND "w" and not "119", because in-game it won't matter, you can use a bitmap font to change between capital and non-capital letters.

So I don't think it's a bug, they just don't expect you to want to use the "lower-case" version of those numbers. Just my two cents!


Meh game development blaugh!
jamesL
14
Years of Service
User Offline
Joined: 31st May 2010
Location:
Posted: 21st Nov 2014 21:45
^ makes sense

but the documentation does say key codes are in the range of 0 to 255
so it seems like it should work
but you're right that in actual use testing for 87 should suffice


GetRawKeyState

Description

Returns 1 if the key code given is currently down. 0 if it is up. This only applies to platforms with a full sized keyboard such as PC and Mac, otherwise all keys will return 0. You can check if a keyboard exists by checking GetKeyboardExists returns 1. Key codes are in the range 0 to 255, anything out of range will return 0.
Yodaman Jer
User Banned
Posted: 21st Nov 2014 21:50
Well in that case, since it is supposed to return a value from the ranges of 0 to 255, then it may very well be a bug.

I don't own AppGameKit V2 so I cannot verify if this is the case.

Do you have another keyboard to try it with?


Meh game development blaugh!
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 21st Nov 2014 23:01 Edited at: 21st Nov 2014 23:02
I don't think this is a bug.

The getRawKeyState command uses the scan codes for the key board as shown in this list in the help files, which is not case sensitive.

As far as I'm aware, the command doesn't use the character string of the key being pressed nor the ascii code.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 21st Nov 2014 23:17
29 games is right. The scan code is the raw code from the keyboard input translated in the this table.

-- Jim - When is there going to be a release?
jamesL
14
Years of Service
User Offline
Joined: 31st May 2010
Location:
Posted: 21st Nov 2014 23:42 Edited at: 21st Nov 2014 23:43
well that's good to know

I did go to the help page for GetRawKeyState and there wasn't a single mention of scan codes or key constants or a link to the help page you posted

all it said was
==========

GetRawKeyState

Description

Returns 1 if the key code given is currently down. 0 if it is up. This only applies to platforms with a full sized keyboard such as PC and Mac, otherwise all keys will return 0. You can check if a keyboard exists by checking GetKeyboardExists returns 1. Key codes are in the range 0 to 255, anything out of range will return 0.

Definition

integer GetRawKeyState( key )

Parameters

key - The key code of the key to check.

==========

neither the 3D-FirstPersonExample example code nor the example code on the GetRawKeyState help page used those key constants

both used plain ordinary numbers

"Parameters: key - The key code of the key to check."

I guess the meaning of "key code" is obvious to experienced programmers, but it sure wasn't to me

would have been really nice to put that link to scan codes right there in the Parameters section,
and would have been even better if they had actually used the key constants instead of numbers in the example code and on the help page

oh well

thanks for the help, much appreciated
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 21st Nov 2014 23:59
Totally agree, jamesL.

AGK Basic has improved, but the examples and demos are littered with literal numbers where constant declarations would have been better.

In fact, the key codes could vary from platform to platform in theory, although they don't in AppGameKit, and it would be better to "import" them.

If it's truly a beginners' system examples should demonstrate good practice, which, unfortunately, they often don't.

-- Jim - When is there going to be a release?
Timshark
17
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 22nd Nov 2014 00:12 Edited at: 22nd Nov 2014 00:26
The scan codes are the same as the ascii code for uppercase. The same goes for the other keys. But even if the scan codes share the same numbers as the ascii codes it is not the same. Rawkey and scancodes is just that: the RAW key.
you could read shift together with any key..
Maybe they should implement the lowercase ascii codes....for rawkey....

I think the reason is the gaming focus of agk...

I never want what I know.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 22nd Nov 2014 00:16
I agree. On Windows the VK (Virtual Key Code) is always the lowest in the range.

There's probably a good cross-platform reason for this!

-- Jim - When is there going to be a release?
Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 22nd Nov 2014 12:46 Edited at: 22nd Nov 2014 12:47
I guess you can check if shift key, and wasd is pressed at the same time, but I don't know if you can check the state of the capslock being lower or upper.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 22nd Nov 2014 16:20
You can also try:

print( getrawlastkey() )

Login to post a reply

Server time is: 2024-11-25 11:49:14
Your offset time is: 2024-11-25 11:49:14