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 / Quick Key Question

Author
Message
SkYnEt
23
Years of Service
User Offline
Joined: 2nd May 2003
Location: United States
Posted: 9th Nov 2003 20:07
Ok ok... I got a good question.

I know leftkey(), and rightkey() But if i wanted a command for the "A" key or the "Q" key, whats the command for that?

Compaq Presario 5127SR | GeForce 2 64mb
1.0ghz Pentium III | 380mb RAM | 1.5mbps Cable
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 9th Nov 2003 20:09
look up "inkey" or "scancode"... check those out, there are many different ways to do it... just look a little into those

ReD_eYe
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 9th Nov 2003 20:12
either
inkey$(a)
or
keystate(scancode) for instance the scancode for 'a' is 30
so
if keystate(30)=1 then dostuff()
clever huh?
oh and before you ask here is a very useful image for finding scancodes


how good am i?


Go on, click on my signature image, you know you want to
Favourite smiley>>>
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Nov 2003 20:15
if you have a scancode chart you could use KEYSTATE()

IF KEYSTATE(scancode value here) = 1
do whatever....
END IF

there is a scancode chart for the numeric key values in the codebase I think, or somewhere on these forums. A=30 if I remember.

`//check for A being pressed
IF KEYSTATE(30) = 1
do whatever....
END IF

hope this helps

-RUST-
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Nov 2003 20:16
ha ha we posted same time!

-RUST-
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Nov 2003 22:34
I've posted all of the key values into the CodeBase too, so you can use 'if keystate(DIK_A) ...' instead of 'if keystate(30) ...' to keep your code a little more readable

http://www.thegamecreators.com/?m=codebase_view&i=2bffc1480b8fde081b95012e1a81604e
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Nov 2003 23:32
true, but is overkill if you are using just a handful of certain keys.

-RUST-
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 10th Nov 2003 06:30
i might have to start using that... would have been nice when i first starting doing this... i wrote a program that would give me the scancodes... then hit each key individually and then pencil the code on a sheet of paper

Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 11th Nov 2003 00:56
question...

how would you make it so when you hit the key it does one operation, but does not repeat, only does it once, until they let go of the key and hit it again... to make a toggle effect?

Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 11th Nov 2003 01:07
I did write a plugin a while back to convert Scancodes to ASCII, which works regardless of the country (as the keyboard layout will change in France / Germany etc.)...

I'll see if I can dig it up for you.

Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 11th Nov 2003 01:26
@Rob K
would that do a toggle effect? like hitting "W" to turn on/off wireframe mode (example)

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Nov 2003 02:45
You do it like this :

qwe
22
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 12th Nov 2003 23:01
I just have a variable inc'd each loop

do
dec wait
if wait<0 then wait=0
if keystate is pressed and wait = 0
do stuff
wait=30
endif
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 12th Nov 2003 23:06


-RUST-
Genesis Rage
22
Years of Service
User Offline
Joined: 5th Oct 2003
Location:
Posted: 23rd Nov 2003 08:26
@IanM
well the that code didnt toggle anything...
its actually for a animation... for landing gear... you hit "L" and it plays an animation of the gear going down... then hit it again to play the animation of them going up... but for some strange reason... it aint working

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Nov 2003 13:49
No, that code just ensures that when you press and hold the W key, the action only occurs once. After re-reading your question, I've come up with this:



As you'll see though, the 'do something' part of my previous code has just become the switching of a value between 0 and 1

Login to post a reply

Server time is: 2026-07-26 15:31:42
Your offset time is: 2026-07-26 15:31:42