KeyboardInkey() ne permet pas d'obtenir le comportement qu'on a quand on tape naturellement sous windows. (il enregistre les released des touches, donc on ne peut l'utiliser pour obtenir les répétitions quand on laisse une touche appuyée par exemple. Ca se ressent aussi quand on utilise shift+un symbol. Exemple typique le '?' qui ne fonctionne pas à chaque fois)
Ce programme fonctionne par contre parfaitement (même si il manque encore les accents qui complètent les lettres... Je vais compléter) et permet d'émuler toute sorte de claviers.
Je vais m'en faire une petite Dll.
Après si tu as une proposition plus simple avec keyboarInkey() et équivalente en confort d'utilisation, je suis bien sûr, preneur.
Code : Tout sélectionner
Xres=1024:yRes=600
TimeRepeat.i=250
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0:MessageRequester("Error", "Can't open the sprite system", 0):End:EndIf
If OpenWindow(0, 0, 0,Xres, Yres, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)=0:MessageRequester("Error", "Can't open windowed screen!", 0):EndIf
If OpenWindowedScreen(WindowID(0), 0, 0, xres, yres, 0, 0, 0)=0:MessageRequester("Error", "Can't open windowed screen!", 0):EndIf
KeyboardMode(#PB_Keyboard_Qwerty)
Structure symbols
key.s[3] ;lowercase 0, uppercase 1 and Alt 2
prevCar.s
timer.d
flag.a
EndStructure
NewList key.i()
NewMap symbols.symbols()
Restore Keys
For i=1 To 65
AddElement(key())
Read.i key()
Next i
Restore Azerty
ForEach key()
Read.s symbols(Str(key()))\key[0];lowercase
Read.s symbols(Str(key()))\key[1];uppercase
Read.s symbols(Str(key()))\key[2];AltGr
Next
DataSection
Keys:
;10
Data.i #PB_Key_1,#PB_Key_2,#PB_Key_3,#PB_Key_4,#PB_Key_5,#PB_Key_6,#PB_Key_7,#PB_Key_8,#PB_Key_9,#PB_Key_0
;Pad 14
Data.i #PB_Key_Pad1,#PB_Key_Pad2,#PB_Key_Pad3,#PB_Key_Pad4,#PB_Key_Pad5,#PB_Key_Pad6,#PB_Key_Pad7,#PB_Key_Pad8,#PB_Key_Pad9,#PB_Key_Pad0
Data.i #PB_Key_Divide,#PB_Key_Multiply,#PB_Key_Subtract,#PB_Key_Add
;letters 26
Data.i #PB_Key_A,#PB_Key_B,#PB_Key_C,#PB_Key_D,#PB_Key_E,#PB_Key_F,#PB_Key_G,#PB_Key_H,#PB_Key_I,#PB_Key_J
Data.i #PB_Key_K,#PB_Key_L,#PB_Key_M,#PB_Key_N,#PB_Key_O,#PB_Key_P,#PB_Key_Q,#PB_Key_R,#PB_Key_S,#PB_Key_T
Data.i #PB_Key_U,#PB_Key_V,#PB_Key_W,#PB_Key_X,#PB_Key_Y,#PB_Key_Z
;space
Data.i #PB_Key_Space
;back
Data.i #PB_Key_Back
;48
;punctuation
Data.i #PB_Key_SemiColon,#PB_Key_Comma
Data.i #PB_Key_Period,#PB_Key_Slash
Data.i #PB_Key_Apostrophe,#PB_Key_BackSlash,#PB_Key_LeftBracket,#PB_Key_RightBracket
Data.i #PB_Key_Minus,#PB_Key_Equals
Data.i #PB_Key_Grave
Data.i #PB_Key_Decimal,86
;total 55
Azerty: ;French keyboard
Data.s "&","1","","é","2","~",Chr(34),"3","#","'","4","{","(","5","[","-","6","|","è","7","`","_","8","\","ç","9","^","à","0","@"
Data.s "1","1","","2","2","","3","3","","4","4","","5","5","","6","6","","7","7","","8","8","","9","9","","0","0",""
Data.s "/","/","","*","*","","-","-","","+","+",""
Data.s "q","Q","","b","B","","c","C","","d","D","","e","E","€","f","F","","g","G","","h","H","","i","I","","j","J",""
Data.s "k","K","","l","L","",",","?","","n","N","","o","O","","p","P","","a","A","","r","R","","s","S","","t","T",""
Data.s "u","U","","v","V","","z","Z","","x","X","","y","Y","","w","W",""
Data.s " "," ",""
Data.s Chr(1),Chr(1),""
Data.s "m","M","",";",".","",":","/","","!","§",""
Data.s "ù","%","","*","µ",""
Data.s "^","¨","","$","£","¤"
Data.s ")","°","]","=","+","}"
Data.s "²","",""
Data.s ".",".",""
Data.s "<",">",""
Qwerty: ;US keyboard
; Data.s "1","!","","2","@","","3","#","","4","$","","5","%","","6","^","","7","&","","8","*","","9","(","","0",")",""
; Data.s "1","1","","2","2","","3","3","","4","4","","5","5","","6","6","","7","7","","8","8","","9","9","","0","0",""
; Data.s "/","/","","*","*","","-","-","","+","+",""
; Data.s "a","A","","b","B","","c","C","","d","D","","e","E","","f","F","","g","G","","h","H","","i","I","","j","J",""
; Data.s "k","K","","l","L","","m","M","","n","N","","o","O","","p","P","","q","Q","","r","R","","s","S","","t","T",""
; Data.s "u","U","","v","V","","w","W","","x","X","","y","Y","","z","Z",""
; Data.s " "," ",""
; Data.s Chr(1),Chr(1),""
; Data.s ";",":","",",","<","",".",">","","/","?",""
; Data.s "'",chr(34),"","\","|",""
; Data.s"[","{","","]","}",""
; Data.s "-","_","","=","+",""
; Data.s "`","~",""
; Data.s ".",".",""
; Data.s "","",""
EndDataSection
Repeat
FlipBuffers()
ClearScreen(#Black)
Repeat:Event = WindowEvent():Until Event = 0
ExamineKeyboard()
shift.i=0
If KeyboardReleased(#PB_Key_Capital)
CapsLock.i=~CapsLock
EndIf
If KeyboardPushed(#PB_Key_PadEnter) Or KeyboardPushed(#PB_Key_Return)
text$+Chr(13)
EndIf
If KeyboardPushed(#PB_Key_LeftShift) Or KeyboardPushed(#PB_Key_RightShift) Or CapsLock
shift=1
EndIf
If KeyboardPushed(#PB_Key_RightAlt)
shift=2
EndIf
ForEach key()
If KeyboardPushed(key())
symbols.s=symbols(Str(key()))\key[shift]
;upcase
If symbols()\timer<ElapsedMilliseconds()
If symbols()\prevCar=symbols
If symbols()\flag=0
symbols()\flag=1
symbols()\timer=TimeRepeat+ElapsedMilliseconds()
Else
symbols()\timer=0
If symbols=Chr(1) ;back
text$ = Left(text$, Len(text$)-1)
Else
text$+symbols
EndIf
symbols()\prevCar=symbols
EndIf
Else
symbols()\flag=0
If symbols=Chr(1) ;back
text$ = Left(text$, Len(text$)-1)
Else
text$+symbols
EndIf
symbols()\prevCar=symbols
EndIf
EndIf
Else
symbols(Str(key()))\prevCar="":symbols()\timer=0
EndIf
Next
StartDrawing(ScreenOutput())
DrawText(0,0,"Type your text... [Escape] To quit")
DrawText(0,40,text$)
StopDrawing()
Until KeyboardPushed(#PB_Key_Escape)