der nachfolgende Code erkennt jede normale Tastatureingabe, außer einige Ausnahmen.
Erkannt werden (getestet):
Nicht (richtig) erkannt werden:a-z
A-z
0-9
/ * - + ! " § $ % & ( ) = ? # ' _ : ; , . < >
| ``
[ESC] [ENTF] [ENDE] [BILD AB] [BILD AUF] [EINFG] [POS 1] [NUM] [DRUCK] [ROLLEN] [RÜCKGÄNGIG] [ENTER] [PAUSE] [WINDOWS-TASTE] [ALT] [ALT-GR] [STRG] [KONTEXT-MENÜ-TASTE]
[F1] .. bis ... [F12]
Tastenkombinationen wie z.B.: [STRG+Z] [STRG+Y] [STRG+ALT+ENTF] ...
Jemand eine Lösung dies zu lösen?
Extra abfragen oder den Code verändern?
Code (funktionstüchtig auf PB 4.50 Windows x86 (= 32 Bit)):
Code: Alles auswählen
; PureBasic 4.50 x86
;- Window Constants
;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#text
EndEnumeration
Global hWindow,hook
Global Dim Array.b(256)
Structure KBDLLHOOKSTRUCT
vkCode.l
scanCode.l
flags.l
time.l
dwExtraInfo.l
EndStructure
If OpenWindow(#Window_0, 255, 175, 600, 300, "Test", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
TextGadget(#text, 50, 30, 490, 220, "")
EndIf
Procedure.l myKeyboardHook(nCode, wParam, *p.KBDLLHOOKSTRUCT)
Char.s = Space(1)
If nCode = #HC_ACTION
If wParam = #WM_KEYUP Or wParam = #WM_SYSKEYUP Or wParam = #WM_KEYDOWN Or wParam = #WM_SYSKEYDOWN
GetKeyboardState_(@Array())
If GetKeyState_($14) > 0
Check.i=ToAsciiEx_(*p\vkCode,*p\scanCode.l,@dummy, @Char.s,0,GetKeyboardLayout_(0));
Else
Check.i=ToAsciiEx_(*p\vkCode,*p\scanCode.l,@array(), @Char.s,0,GetKeyboardLayout_(0));
EndIf
If Check.i And wParam = #WM_KEYDOWN
SetGadgetText(#text, GetGadgetText(#text)+char.s)
EndIf
EndIf
EndIf
ProcedureReturn CallNextHookEx_(hook, nCode, wParam, *p)
EndProcedure
#WH_KEYBOARD_LL = 13
hook = SetWindowsHookEx_(#WH_KEYBOARD_LL,@myKeyboardHook(),GetModuleHandle_(0),0)
If hook = 0: End: EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
MFG,
Tombi
Edit: Am besten wäre es wohl, vorallem bei "Zeichen" wie z.B. die Enter-Taste einfach [ENTER] auszugeben.
Muss ich nun für jeden Befehl eine eigene Abfrage einbauen, ob es gerade dieser Befehl ist?
Und wie löse ich das mit Tastenkombinationen?