ASCII code from keyboard layout

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GIDO.

here is a program to check the ASCII code of the characters/keyboard
layout .

Dim ks.w(256)
InitKeyboard()
If OpenWindow(0,100,200,200,100,#PB_Window_SystemMenu ,"ASCII CODE")

layout=getKeyboardLayout_(0)
For i=0 To 255
ks(i)=VkKeyScanEx_(i,layout) ; Table for ASCII code/default keyboard layout
Next i

Repeat
sh=0:ctl=0:alt=0:ascii=0:vk=0
If GetAsyncKeyState_(#VK_shift)=-32768:sh=1:EndIf;shift
If GetAsyncKeyState_(#VK_Menu)=-32768:alt=1:EndIf; Alt
If GetAsyncKeyState_(#VK_Control)=-32768:ctl=1:EndIf; Control

For i=20 To 255
k1=GetAsyncKeyState_(i)
If k10:vk=i:EndIf ; VK = virtual key
Next i
codet=vk+256*sh+1536*alt+512*ctl ; value with shift and alt
For i=0 To 255
If codet=ks(i):ASCII=i:EndIf ; comparison with the table
Next i
If ascii0
ascii$=Chr(ascii); code ASCII of the keypushed
StartDrawing(WindowOutput())
DrawingMode(0)
spa$=" "
DrawText(spa$)
DrawText(ascii$+" => code ASCII="+Str(ascii)+" ")
StopDrawing()
Else
ascii$=""
EndIf
EventID.l = WaitWindowEvent()

If EventID = #PB_Event_CloseWindow
Quit = 1
EndIf

Until Quit = 1

EndIf
End

Now, my problem is to detect dead keys to have the ascii code for
the combination of 2 characters (¨ and e = ë )?

I want also the possibility to change the language in cyrillic for example when I use "Drawtext".

Thank you .