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 / Keyboard scancode is not consistant

Author
Message
Ekko
22
Years of Service
User Offline
Joined: 27th Apr 2004
Location:
Posted: 16th Mar 2010 03:43
Hello,
Not sure if this is a potential bug or a known issue we have to program to compensate for...

My Sony Vaio laptop uses the standard scancode that is shown throughout the forum, but my 2 PC's with wireless LogiTech keyboard/mouse setup has 2 changes in the scancode assignments that I've noticed:

Tilda, normally 41 is something like 146.
Left Braket, normally 26 is somrhting like 147.

Not sure what the exact scancode returned was, I noticed the problem about 2 weeks ago and I'm not able to check at the moment.
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 16th Mar 2010 03:58
Some keyboards will have different scancodes for certain keys. I have a French keyboard, and instead of 'WASD' I use 'ZQSD'. As long as scancodes are used I don't have to alter the configuration (as the scancodes are dependant on the placement of the keys, not which keys they are), but unfortunately some games seem to like automatically figuring out the scancodes of 'WASD' and use them, which results in a very strange finger placement on this keyboard.

Of course, this can also be problematic, as the tilde key is often used to bring up the console in some games, but with a different scancode it usually won't. I'd recommend simply allowing the key configuration to be changed easily, perhaps from a text file. On different keyboards based on the same layout (such as UK/US QWERTY) there should only be minor layout differences; the majority of the keys should have the same scancodes.
Ekko
22
Years of Service
User Offline
Joined: 27th Apr 2004
Location:
Posted: 16th Mar 2010 04:24
Thanks agian Benjamin. That's exactly the point which I found the problem... trying to bring up the console in my game. I already have a the ability to change keys. The problem is I have the key config saved in a plain text file in the following format, for example:


I then have a function to read this text document and converts it into scancode.

Is there anywhere in the registry that I could find what keyboard layout the user has? I'd like to stay with saving in plain text format because it seems to be common practice with a lot of major titles.
jfroco
16
Years of Service
User Offline
Joined: 1st Dec 2009
Location: Chile
Posted: 16th Mar 2010 04:30
Hi Ekko,

As I use a Latin American Spanish keyboard I always have problems with games that use tilde and brackets keys .

You can search the forum for INI config files and you will find how to load options from a config file.

Best regards

JF
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 16th Mar 2010 05:14
There are some useful keyboard functions in user32.dll that can be used when managing keyboard input. Here's some code for some of the most useful ones:

1. Obtain the keyboard layout:



A list of primary language and sublanguage IDs can be found here. Note that there are probably several layouts which may be the same or have only minor differences.

2. Get a key's name based on its scancode:



However it returns the name in the currently selected language, and while it returns the name for most keys it does not seem to work for certain keys such as up/down/left/right/home/etc.

3. Determine the scancode of a key based on its character value (most useful):

Ekko
22
Years of Service
User Offline
Joined: 27th Apr 2004
Location:
Posted: 20th Mar 2010 04:00
Thanks Benjamin! Exactly what I'm looking for.
Ekko
22
Years of Service
User Offline
Joined: 27th Apr 2004
Location:
Posted: 18th Apr 2010 04:12
So I've had time to finally implement the code into my project but i found a little issue: Every key works perfect... except the numpad enter key!?!

I didn't see it in the list of virtual keys from microsoft or any other web pages out threre, so I wrote some code to find it thinking that maybe it's refered to by some weird name. On my system the numpad enter key's scancode is 156 (according to DBPro scancode() funciton) so I wrote the following code to try to find out which VK key numer it is:




Any thoughts? ... I'm looking at you Benjamin.

Login to post a reply

Server time is: 2026-07-26 12:50:22
Your offset time is: 2026-07-26 12:50:22