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.

Newcomers AppGameKit Corner / scan code for "+"

Author
Message
guy_design
1
Years of Service
User Offline
Joined: 1st Mar 2017
Location:
Posted: 27th Dec 2017 03:22
My app want to check calculator sign but AGK2 don't have scan code for "+" .It can use "=" button instead for standard keyboard , but I want to use number pad that "+" button not work.
blink0k
AGK Developer
5
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th Dec 2017 03:49
GetLastChar() will return the last key pressed including + - =
Unfortunately GetRawKeyPressed/Released() do not report those keys
guy_design
1
Years of Service
User Offline
Joined: 1st Mar 2017
Location:
Posted: 27th Dec 2017 04:19
blink0k THANKS SO MUSH
adambiser
AGK Developer
3
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 27th Dec 2017 05:26
These are the values (at least for Tier 1 code)
107 = numpad plus
192 = numpad divide (this is the same code as the grave accent/tilde key and seems to be a bug, should be 191 to match the forward slash key)
106 = numpad multiply
189 = numpad subtract (also non numpad minus key)
190 = numpad point (also keyboard period)
13 = numpad enter (also keyboard enter)
These don't match what other things use as key codes.

I think they work with GetRawKeyPressed and GetRawKeyReleased.
Rick Nasher
1
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 27th Dec 2017 22:35 Edited at: 27th Dec 2017 22:57
Might be handy:


Call once from start and then for instance in main loop like:

If GetRawKeyPressed(KEY_ESC) then exit
Rich Dersheimer
AGK Developer
Silver Codemaster
9
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Jan 2018 18:39
@Rick Nasher - Nice! I use the same thing, but mine is a text file instead of a function, I just #include it in main file.
Rick Nasher
1
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 6th Jan 2018 00:23
@Rich Dersheimer
Quote: "but mine is a text file instead of a function, I just #include it in main file."


That's actually an even better solution. I'm still thinking in a Blitz3D type of coding, hehehe.

Thanks and cheers.
Rick Nasher
1
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 20th Feb 2018 22:07 Edited at: 20th Feb 2018 22:08
One drawback of this approach is that included files will be added to *end* of the program, which may lead to undesirable effects in some cases.
To avoid this I put the Functions into the Include file, and call these. E.g:

#include "init_vars" // contains the variables between Function initialize_variables() and EndFunction.

initialize_variables() // call the function to make sure it's run before the variables are needed somewhere.
adambiser
AGK Developer
3
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 20th Feb 2018 22:10
PHeMoX
User Offline
Joined: 9th Jan 2018
Location:
Posted: 21st Feb 2018 01:23
Cool, I had no idea there was such a thing as #insert

I also like the trick of doing it like this:

GetRawKeyState(asc("W"))

Unfortunately, I can't test if GetRawKeyState(asc("+")) works on my laptop as I don't have a keypad on there.

Alternatively, I use this code to show what key was pressed:



This should go in your main Do Loop .
adambiser
AGK Developer
3
Years of Service
User Offline
Joined: 16th Sep 2015
Location: US
Posted: 21st Feb 2018 02:14
@PHeMoX: ASCII codes are not the same thing as key codes. Some match, like uppercase letters, but not much else.
PHeMoX
User Offline
Joined: 9th Jan 2018
Location:
Posted: 21st Feb 2018 09:32
Quote: "ASCII codes are not the same thing as key codes. Some match, like uppercase letters, but not much else."


Yeah true, I knew it requires uppercase letters to work (however it does respond to pressing those letter keys without shift) which is why I tend to use mostly just the code that returns the key code using Print() command. Super quick and I can leave it in my code for as long as needed.

Rick Nasher
1
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 22nd Feb 2018 16:20 Edited at: 22nd Feb 2018 16:43
Quote: "If you use #insert instead of #include, the file is added where the #insert is."


That's awesome. Thanks, AppGameKit has so many things to make life easier, more structured and readable.

Note to absolute beginners reading this thread: It might not be a good idea to use #insert on everything though. Is good for variable initialization, but less for other stuff.
For instance parts of world setup might need to be available again as a function when restarting a game after it's game over.

I also like FoldStart - FoldEnd. Very handy to quickly move things out of the way if too cluttered and want more overview, which is in essence bad coding but hey, if it work it works.
blink0k
AGK Developer
5
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 4th Mar 2018 04:02
The thing about the plus (+) key is that it is the equals (=) key in combination with the shift key so you should test for the equals key AND the shift key
PHeMoX
User Offline
Joined: 9th Jan 2018
Location:
Posted: 7th Mar 2018 21:28
Quote: "The thing about the plus (+) key is that it is the equals (=) key in combination with the shift key so you should test for the equals key AND the shift key "


Yeah, but there's another + key on the keypad area on your keyboard. Well, as long as you're not on a laptop of course.

Login to post a reply

Server time is: 2018-10-23 07:57:59
Your offset time is: 2018-10-23 07:57:59