API - Etat général de toutes les touches du clavier
Publié : mer. 26/sept./2007 0:30
Suite au léger bug clavier que rencontre Pollux, kaeru (forum UK) m'a fait découvrir une fonction de l'API : GetKeyboardState_()
Voici un des deux exemples d'affichage simultané de l'état de chaque touche.
Voici un des deux exemples d'affichage simultané de l'état de chaque touche.
Code : Tout sélectionner
Structure FFmap
key.b[256]
EndStructure
Global Dim Keys.FFmap(1)
Procedure FunStd()
Protected WinX.L
WinX = OpenWindow(-1, 0, 0, 600, 300, "GetKeyboardState - Map of the keyboard", $00CF0001)
If WinX
MenuX.L = CreateMenu(-1, WindowID(WinX) )
If MenuX
OpenSubMenu("File")
MenuItem($1F0, "Quit")
CloseSubMenu()
Static Exit.L = 0
Repeat
;____________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Swaping = 1 - Swaping
If GetKeyboardState_(@Keys(Swaping) )
StartDrawing(WindowOutput(WinX) )
For y = 0 To 15
For x = 0 To 15
N = (y << 4) + x
If Keys(Swaping)\Key[N] <> Keys(1 - Swaping)\Key[N]
xx = (x + 1) << 5
yy = (y + 1) << 4
Box(xx, yy, 32, 16, #Black)
Box(xx, yy, 31, 15, #White)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(xx, yy, Str(Keys(Swaping)\Key[N]) )
EndIf
Next
Next
Line(31, 15, 0, 256, #Black)
Line(31, 15, 512, 0, #Black)
StopDrawing()
EndIf
;____________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Delay(5)
eWindow = WindowEvent() ; << Is this the problem?
aWindow = EventWindow()
Select eWindow
Case #PB_Event_Repaint
For i = 0 To 255
Keys(0)\Key[i] = 254
Next
StartDrawing(WindowOutput(WinX) )
For x = 0 To 15
DrawingMode(#PB_2DDrawing_Transparent)
DrawText((1 + x) << 5 + 8, 0, RSet(Str(x), 2, "0") )
DrawText(4, (1 + x) << 4, RSet(Str(x << 4), 3, "0") )
Next
;Line(0, )
StopDrawing()
Case #PB_Event_CloseWindow: Exit = $1
Case #PB_Event_Menu : eMenu = EventMenu(): If eMenu = $1F0: Exit = $1: EndIf
Case #PB_Event_Gadget : eGadget = EventGadget():
EndSelect
Until Exit = 1
EndIf
EndIf
EndProcedure
FunStd()