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 / Getting value of letter for keystate()?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Dec 2010 18:07
Hi all,


How can I return the value needed to check if the button is pressed with keystate, if I have to get the value from a string? I have this:

if keystate(asc(hotkey$))=1

but asc("m") doesn't return the same value as when I use scancode() and press m. Is there a command for this?

TheComet

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Dec 2010 18:17 Edited at: 2nd Dec 2010 18:22
Scancodes aren't the same as ASCII values. I don't think there's a native way to get the name of a key based on a scancode in DBP, but it's certainly possible through a WinAPI call (see this function). I'll post an example later if I find time.

[edit] Actually I see you want to do the opposite, in which case there's a function to do that somewhere in here.
MSon
22
Years of Service
User Offline
Joined: 13th Jul 2004
Location: Earth, (I Think).
Posted: 2nd Dec 2010 20:48
You could just run this to find out what the scan code is


Or if your using the DarkBasic Editor, check the menu "Tools\KeyState Helper"

getting the number this way you dont have to do conversions.

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Dec 2010 20:52
Quote: "You could just run this to find out what the scan code is"


You'd have to do this with every keyboard and every locale possible, which I don't think is feasible.
MSon
22
Years of Service
User Offline
Joined: 13th Jul 2004
Location: Earth, (I Think).
Posted: 2nd Dec 2010 21:04 Edited at: 2nd Dec 2010 21:25
Here you go then, this does as Benjamin suggested, using a DLL to convert the scancode to a key string entry, you should be able to change this to do what you want.



EDIT: This reverses it like you want


Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 3rd Dec 2010 02:15
You could always use INKEY$() but that's old school.



Mugen Wizardry
User Banned
Posted: 3rd Dec 2010 02:28 Edited at: 3rd Dec 2010 02:29


CHECK OUT SOME MUSIC FROM MY NEW TECHNO CD! TECHNOKINESIS
http://www.youtube.com/watch?v=4a8KedfgVv0
ALSO, CHECK OUT MY NEW TECHNO CD AT Amazon.com!
miso
16
Years of Service
User Offline
Joined: 16th Jun 2010
Location: Budapest, Hungary, 127.0.0.1
Posted: 4th Dec 2010 08:49 Edited at: 4th Dec 2010 09:02
I use this. It's not my original idea, but so nice I started to use.

Usage in main program for example:



Write this into a separete include source file, then add it to your project:



(I hope I didn't misunderstand your needs)

No place like 127.0.0.1 .
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Dec 2010 00:18
Thanks a lot guys!

I decided to go with miso's method, I see that it is clean to read, and doesn't require any conversions. So thanks to everyone, I will be able to use the dll for conversions in the editor

TheComet

Login to post a reply

Server time is: 2026-07-21 18:58:30
Your offset time is: 2026-07-21 18:58:30