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.

DarkBASIC Professional Discussion / Keystate number keys

Author
Message
Wu dynasty
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location: In a democracy
Posted: 8th Feb 2013 17:09
I am making a question game and for ABC, I would like to use the 1,2,3,4 number keys. How would I do that. What command would I use.
Thanks,
Nathan
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 8th Feb 2013 20:12 Edited at: 8th Feb 2013 20:12
If inkey$()="1" then
If inkey$()="2" then
If inkey$()="3" then
If inkey$()="4" then

or

if scancode()=2 then
if scancode()=3 then
if scancode()=4 then
if scancode()=5 then

or

if val(inkey$())=1 then
if val(inkey$())=2 then
if val(inkey$())=3 then
if val(inkey$())=4 then

D.D.
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 8th Feb 2013 20:22
All of what Derek Darkly said works, however those commands have a problem: it will only register one key press at a time because the inkey$ command returns the most recent key pressed. There is a better command which can register any amount of presses at once and will return a 0 or 1 when a given key is pressed.

value (boolean) = keystate(key)

This is a chart originally created by Scraggle that shows the keystate values for common keys:



So, for the number keys 1-4 you'd use this code:



MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 9th Feb 2013 00:16
Pro-Tip:

While in the DBPro IDE, press

Quote: "CTRL+K"


Have fun



HWT
21
Years of Service
User Offline
Joined: 1st Apr 2005
Location: Earth
Posted: 9th Feb 2013 01:29
Here's a very simple example. If you want more explanation feel free to post back here.

Example:



Hello World Tommorrow
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 11th Feb 2013 23:44
Great info on KEYSTATE! I'd never used it before.

I don't think Wu's program will require simultaneous keys, but this is definitely the fail-safe way to go.

D.D.
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Feb 2013 22:25
Quote: "if val(inkey$())=1 then
if val(inkey$())=2 then
if val(inkey$())=3 then
if val(inkey$())=4 then"

This is not such a good idea because every non-numeric key will have a value of zero, so "0" will be treated the same as a letter. The extra conversion will also slow things down.

Keystate is great because you can customize key-bindings.

^ That's what she said.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 14th Feb 2013 10:35
*Smart-ass incoming*

You could use the entry buffer, that way you don't have to poll your keys every frame and it's the most reliable way to accumulate user inp-

You know what, never mind. Just go with the advice above.

TheComet

http://blankflankstudios.tumblr.com/
"ZIP files are such a retarded format!" - Phaelax
Wu dynasty
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location: In a democracy
Posted: 14th Feb 2013 17:26
thank you all except for the guy whos eating my ponies.

You are entering the Wu Dynasty. Boomshakalaka
-Nathan
ViktorLazarev
13
Years of Service
User Offline
Joined: 20th Feb 2013
Location: On a PC Runing OSx with a VBox Linux :D
Posted: 20th Feb 2013 17:27
Ponies are not that good to eat
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 21st Feb 2013 10:28
(Completely off-topic question) Hey Wu, do you happen to play Dynasty Warriors Online?
ViktorLazarev
13
Years of Service
User Offline
Joined: 20th Feb 2013
Location: On a PC Runing OSx with a VBox Linux :D
Posted: 21st Feb 2013 17:14
What the heck is Dynasty Warriors Online?
Wu dynasty
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location: In a democracy
Posted: 21st Feb 2013 17:16
I used to, but not anymore. I have always thought that it would be cool to have a dynasty named after me.

You are entering the Wu Dynasty. Boomshakalaka
-Nathan
ShaunMartin
13
Years of Service
User Offline
Joined: 21st Feb 2013
Location:
Posted: 21st Feb 2013 17:28
no but rabits are.
ViktorLazarev
13
Years of Service
User Offline
Joined: 20th Feb 2013
Location: On a PC Runing OSx with a VBox Linux :D
Posted: 25th Feb 2013 17:27
Rabits?

http://youtube.com/user/ViktorLazarev
Life is never good without a computer.
ViktorLazarev
13
Years of Service
User Offline
Joined: 20th Feb 2013
Location: On a PC Runing OSx with a VBox Linux :D
Posted: 15th Mar 2013 16:40
You know that in the newer versions of DarkBASIC Pro free have a keystate helper. For example:


http://youtube.com/user/ViktorLazarev
Life is never good without a computer.

Login to post a reply

Server time is: 2026-07-07 12:28:40
Your offset time is: 2026-07-07 12:28:40