Crossplatform keyboard input library? (mostly solved)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
elsairon
Posts: 207
Joined: Jul 02, 2005 14:51

Crossplatform keyboard input library? (mostly solved)

Post by elsairon »

Looking for a library that has good cross platform keyboard handling and keyboard detection (for example, detect and support azerty, qwerty, etc. keyboards).

The only libs I have heard of mentioned for this are the curses variants.

Are there any other good ones?
Last edited by elsairon on Jan 12, 2008 20:07, edited 1 time in total.
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Post by notthecheatr »

As far as keyboard input, look no further than our very own Inkey, Input, and MultiKey.

As for detecting keyboards, I'm not sure. in Windows there's almost certainly an API function for that, probably in XWindows too (in case you want linux support), and in DOS your best bet might be to ask the keyboard itself. The problem is, I don't remember reading anything about that in the standard PS/2 keyboard API, meaning it would probably be something non-standard.

In fact, keyboard mapping is usually done at the software level, since anyone can for example change the keys around on their keyboard, rendering it a different key mapping. Usually it's up to the OS to do that, so Windows/Linux will probably do it for you but DOS I doubt. They only have the keyboard layouts for various countries/languages. The simplest cross-platform method that wouldn't even need any API calls might be to ask the user to press a few keys (such as QWERTYUIOP) and detect which layout it probably is - but that has its problems. Even better your program could have a settings menu where the user may set his own keyboard configuration.

But no, I don't know of any specific libraries for that kind of thing.
elsairon
Posts: 207
Joined: Jul 02, 2005 14:51

Post by elsairon »

The main reason I ask is that I have had some users reporting that certian keys do not work when using inkey input routines.

Specifically the numpad.

Setting up constants for scancode values in advance seems to not work for all users.

Is there a way to detect what values are bound to keys, and then set the scancode values appropriatly?

I'm guessing the issue is that this is hardware and low level OS function dependant .
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

Post by KristopherWindsor »

You could add a control setup to each program you write.
Like:

Code: Select all

Print "Press Up Key for Game"
For a as integer = 1 to 128
  if multikey(a) then key_up = a
next a
It would fix Lachie's number keypad, anyway (assuming his keyboard works at all). ;-)
notthecheatr
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT
Contact:

Post by notthecheatr »

I myself prefer simply to not use the numpad for most things, it's too much of a hassle and most people prefer WASD or arrow keys anyways.

I think the problem in that case may be related to whether Num Lock is turned on or off, which most average users are too dumb to know - which is another reason simply to not use it. The other thing is some people have laptops, myself included, and on my laptop uses the "numeric keypad" is a pain in the butt, as it involves a lot of Fn keypresses... much easier just to use arrows or WASD.

That's my idea on it anyways, take it or leave it :P
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

The numeric keypad is difficult to use in FB programmes. See

http://www.freebasic.net/forum/viewtopi ... highlight=

Garvan
elsairon
Posts: 207
Joined: Jul 02, 2005 14:51

Post by elsairon »

Multikey does not return events for numpad keys with respect to the numlock toggle. Inkey does.

Perhaps Multikey could be improved, were would be a good place to start with this?

Edit: After some forum searching I notice this issue has been around and has no clear solutions.

Library that allows checking scroll/caps/num lock toggle state supporting whatever platforms fb supoports. If I was going to start a project like this what should I do first? (I have not done anything like this before)
Kot
Posts: 336
Joined: Dec 28, 2006 10:34

Post by Kot »

Old legends say that you can control CapsLock, NumLock and ScrollLock by controlling byte at address &h417, but probably Windows won't let you get there. Peek and Poke would be useful ;-) That's the address where BIOS keeps keyboard control keys state. For example bit 7 keeps Insert, bit 6 CapsLock and bit 3 ctrl-NumLock.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

Under Windows (98 and later) you can toggle Num Lock with code like this:

Code: Select all

#include "windows.bi"

dim ki(1) as INPUT_

ki(0).type = INPUT_KEYBOARD
ki(0).ki.wVk = VK_NUMLOCK
ki(1).type = INPUT_KEYBOARD
ki(1).ki.wVk = VK_NUMLOCK
ki(1).ki.dwFlags = KEYEVENTF_KEYUP
SendInput( 2, @ki(0), sizeof(INPUT_) )
And for Caps Lock use VK_CAPITAL.

And you can get the toggle state with GetKeyState(VK_NUMLOCK), etc.
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

I posted one possible cross platform solution for Num Lock here

http://www.freebasic.net/forum/viewtopi ... 0521#90521


Garvan
elsairon
Posts: 207
Joined: Jul 02, 2005 14:51

Post by elsairon »

MichaelW, thanks. This will work well for the windows part.

Thanks Sisophn2001, your solution solves my main concern.
Post Reply