Hi all,
the function translates the scancodes in key name and stores the result in an array.
It uses the user32 dll, so it makes the difference between QWERTY and AZERTY keyboards.
It is very simple to use(just one array to read):
remstart
==============================================================
= Title : GetListNameKey
= Author : Silverman
= Date : august 2013
= Update :
= Version: 1.0
==============================================================
Comments : Function which stores in an array a list of names
of keyboard keys
==============================================================
remend
sync on
dim NameKey$(255)
`fill the NameKey$() array
GetListOfNameKey()
do
cls
print "press a key..."
print
`the two ways work: scancode() or keystate()
choice=0
if choice=0
`we test scancode() command
scancod=scancode()
key_state=scancod
else
`we test keystate() command
for scancod=1 to 255
key_state=keystate(scancod)
if key_state=1 then exit
next scancod
endif
if key_state<>0 then print "The pressed key is : ",NameKey$(scancod)
sync
loop
end
function GetListOfNameKey()
`get free memblock
memb=0
repeat
inc memb
if memblock exist(memb)=0 then exit
until memb>255
if memb=256
break "No memblock available"
end
endif
sizebuffer=32
make memblock memb,sizebuffer
`get free dll
dll=0
repeat
inc dll
if dll exist(dll)=0 then exit
until dll>255
if dll=256
break "No dll available"
end
endif
load dll "user32.dll",dll
`get name of keys
KPointer = Get Memblock ptr(memb)
for scancode=1 to 255
c$=""
str_len= call dll(dll, "GetKeyNameTextA", (2^25)+(scancode*65536), KPointer, sizebuffer)
`
if str_len<>0
`make string
for i=0 to sizebuffer-1
c$=c$+chr$(Memblock Byte(memb,i))
next i
`clear buffer
for i=0 to sizebuffer-1
write memblock byte memb,i,0
next i
else
c$=NameKey$(scancode&127)
endif
`fill the array
NameKey$(scancode)=c$
next scancode
`free memory
delete memblock memb
delete dll dll
endfunction
EDIT :Tested, it makes the difference between QWERTY and AZERTY keyboards.
Small change in the code.
DirectX 9.0c (February 2010)/ DBClassic v1.20