This evening I tested Michael Bujardet his solution again and came to the conclusion that for some keys, the result is wrong. Please take a close look to the following dictionary which converts the characters to numbers :
dico.value("&") = “1”
dico.value("") = “2”
dico.value(chr(34)) = “3”
dico.value("’") = “4”
dico.value("(") = “5”
dico.value("-") = “6”
dico.value("") = “7”
dico.value("_") = “8”
dico.value("") = “9”
dico.value("") = “0”
dico.value(")") = “”
dico.value("=") = “+”
This is a perfect French convertion for AZERTY. However the Belgium AZERTY is slightly different. Here are the results for a Belgian AZERTY keyboard :
= 6
! = 8
So I searched again for a way to determine the state of the Caps lock key and switched it “ON” (for AZERTY) or “OFF” (for QUERTY) when nummeric input without the use of the SHIFT key. The following routine is for use with a barcode scanner but can be used for other appliances too.
First create a new method with the name “InputNummeric” and give it one parameter “blnAZERTY” of type “Boolean”. Then copy the following code in the body of this method :
[code]// This function make sure the Caps lock key is always in the
// correct position to return a nummeric value depending
// on the type of keyboard. Works only in Windows.
// blnIsAZERTY values :
// blnIsAZERTY = False : keyboard is QUERTY
// blnIsAZERTY = True : keyboard is AZERTY
// blnStateCapsLock values :
// blnStateCapsLock = False : Caps lock key OFF
// blnStateCapsLock = True : Caps lock key ON
//
// When blnIsAZERTY equals “True” then the Caps lock key
// should be “ON” when producing nummeric input without
// pressing the “shift” key.
//
// Credits :
// Jim Cramer : for detecting and switching the state
// the state of the caps lock key
// Michael Bujardet : sharing his code with me and putting
// me on the right track after being lost.
// Thank you both very much for your sharing your knowledge with me.
#if TargetWin32
declare Function GetKeyState lib “User32” (key as Integer) as Integer
Declare Sub keybd_event Lib “User32” (ByVal vk as Byte, ByVal sc as Byte, _
ByVal flags as Integer, extinfo as Integer)
Select Case blnIsAZERTY
Case True // Keyboard is AZERTY
// Caps lock has to be “ON” to type numbers without shift
If Not (GetKeyState(&h14) > 0) then
// Caps lock is OFF,
// switch it on
keybd_event(&h14, &h14, 1,0)
keybd_event(&h14, &h14, 3,0)
End If
Case False // Keyboard is QUERTY
// Caps lock has to be “OFF” to type numbers
If GetKeyState(&h14) > 0 Then
// Caps lock is ON,
// switch it off
keybd_event(&h14, &h14, 1,0)
keybd_event(&h14, &h14, 3,0)
End If
End Select
#Endif[/code]
Now wherever you want to check and if necessary alter the state of the caps lock key for nummeric input, type the following code inside the “TextChange” event handler of a TextField object :
When they keyboard is AZERTY :
InputNummeric(True)
When the keyboard is QUERTY :
InputNummeric(False)
You also have to type the same calls in the “GotFocus” event handler of the textfield.
Now you can test it if you have a barcode scanner. If you do not have a barcode scanner, just enter a number with the keys on the alphanummeric part of the keyboard.
There is only one problem in one particular situation :
When the Caps lock is in state “OFF”, the text cursor is in the textfield and you call InputNummeric inside the “KeyDown” event handler of the textfield, the first character is wrong. For example, the first number of the barcode is “1”, then you will still get “&” instead. Anybody having a solution for that problem?
I like to share this method because I received so much support here within this community.
Chris