Page 1 of 1

keyboard mapping on windows, linux and mac

Posted: Thu Jul 21, 2011 4:45 pm
by delikanli_19_82
hello everybody,

i have tried some ways to create a "keyboard controller" which shell be cross-platform usable on windows, linux and mac and shell help to create own input-box gadgets. but i am not happy with that, what i have.

the task is:

- to find out, which keyboard map is currently used by the user (on all os!!). It can be, that the environment language is german, but the user uses an english or french keyboard layout.

- if you hit on a keyboard-key, it shell return the current unicode-number and if you write it in a string, the unicode character shell be written.

- it shell be doable to find out, if one key or several keys are pressed.

there is a keyboard-listener-procedure which will run in the main-loop:

Code: Select all

event.l = WaitWindowEvent()

keyboard_controller()

this procedure write the current keyboard information into a structure like keyboard_map which contains the following information:

Code: Select all

Structure keyboard_map
  list keys_n.l() ; Here are the unicode numbers of the pressed keys. minimally one.
  list keys_s.s() ; Here are the unicode characters. minimally one.
  single_key_press.b ; If #False, no need to parse the lists
  alt_pressed.b
  control_pressed.b
  command_pressed.b ; Under Windows and Linux it's the Windows-Popup-Menu-Button, under Mac the Mac-Command-Button
  alt_gr_pressed.b
  shift_pressed.b
  caps_lock_on.b
  num_lock_on.b
  keymap.s ; Based of the Operating System's current KeyMap, here will be written an universal language id like "de-de-q", "tr-tr-f", "en-us" etc. "q" stands for qwerty-layout,"f" for "f-layout" on keyboard.
EndStructure
In a further structure "keyboard_user_maps" you'll need to get all available keyboard layouts defined by the user. Under Windows this are the keyboard layouts you can set up by the "region..." settings. If you will done, you see at the taskbar, right, down, the current keymap language id like "EN" or "DE". If you click on it, all the maps your selected are available in a popupmenu to choose one of them. Under Mac you can do it in a similar way and also under linux:

Code: Select all

Structure keyboard_user_maps
 primary_lid.s ; Primary Language ID
 current_lid.s ; The language map, which is currently used
 list avai_lids.s() ; All available keymaps of the user
EndStructure
The Language ID definition will not be named like in the operating system's standard. It will named in an universal way, so it can used on all three os in the same way:

PRIMARY-LANGUAGE + COUNTRY + LAYOUTTYPE. Sample:

DE-DE-Q >> means the germany keymap for germany and in the QWERTZ model.
EN-US-Q >> means the english keymap for usa and in the QWERTY model.

etc.

my problem to work with the keyboard input is:

i don't want to get a virtual key or ascii or ansi or whatever. i only want the unicode-number of a key which is pressed based on the currently using keymap of the system.

i want to find out, how to get an array of all pressed keys within 8ms or in a specific millisecond-bandwidth.

there are some stuff for windows and mac, but not really usable i guess for that, what i want to do. for linux, i have nothing yet.

Till now, i tried to create own maps for each keymap-id on an os. but this is to much work that i cannot do alone. furthermore it is not really useable, because i am also not available to use multi keypress on all three os's.

now i guess it could be a better way to find the unicode-number itself, that fires if a key is pressed. I think, all three os should internally work with unicode. otherwise, i am not sure, how to interact with each keymap.

have someone any idea? maybe better solutions?

kind regards

:-(