ich habe mal kleine Beispiele gebaut:
Die Konstanten #PB_Key_PadEnter und #PB_Key_Return gibts bei InitKeyboard(), InitSprite() und Co.
Code:
If InitSprite() And InitKeyboard() And OpenScreen(800,600,32,"Test")
Paused = #False
Debug " enter loop "
Repeat
FlipBuffers()
If StartDrawing(ScreenOutput())
ExamineKeyboard()
DrawingMode(0)
DrawText(20, 20, "Program is running... (ESC to exit.)")
If KeyboardPushed(#PB_Key_PadEnter)
DrawText(20, 40, "Key PadEnter ...") :Debug #PB_Key_PadEnter ;== 156
EndIf
If KeyboardPushed(#PB_Key_Return)
DrawText(20, 60, "Key Return ...") :Debug #PB_Key_Return ;== 28
EndIf
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIf
In Windows Applicationen kann man (scheinbar) zwischen Return und Enter nicht wirklich unterscheiden.
Code:
EnableExplicit
Procedure Trace(Pre$, Key = 0)
Protected t$, k
If key <> 0
t$ = ": " + RSet(Str(key), 3) + ", 0x" + RSet(Hex(key), 2, "0") + ", '" + Chr(key) + "'"
If key = #VK_RETURN : t$ + ", (Return or Enter)" : EndIf
EndIf
AddGadgetItem (0, -1, LSet(Pre$, 15) + t$)
SetGadgetState(0, CountGadgetItems(0) - 1)
EndProcedure
; MSDN - HELP WM_KEYDOWN
;
; wParam
; The virtual-key code of the nonsystem key. See Virtual-Key Codes.
;
; lParam
; The repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown following.
;
; Bits Meaning
; 0-15 The repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
; 16-23 The scan code. The value depends on the OEM.
; 24 Indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
; 25-28 Reserved; do not use.
; 29 The context code. The value is always 0 for a WM_KEYDOWN message.
; 30 The previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
; 31 The transition state. The value is always 0 for a WM_KEYDOWN message.
;
; Return value
; An application should return zero if it processes this message.
;
Procedure callback(hwnd, umsg, wparam, lparam)
Protected result = #PB_ProcessPureBasicEvents
Select umsg
Case #WM_SYSKEYDOWN : Trace("WM_SYSKEYDOWN", wparam)
Case #WM_SYSKEYUP : Trace("WM_SYSKEYUP", wparam)
Case #WM_KEYDOWN : Trace("WM_KEYDOWN", wparam)
Case #WM_KEYUP : Trace("WM_KEYUP", wparam)
EndSelect
ProcedureReturn result
EndProcedure
Procedure main()
If OpenWindow(0, 0, 0, 640, 480, "Teste Keyboard ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListViewGadget(0, 10, 10, 620, 460, $4000) ;' #LBS_NOSEL == $4000
SetGadgetFont(0, LoadFont(0, "consolas", 8))
AddGadgetItem (0, -1, "Einfach mal eine Taste drücken und schauen was passiert! ")
SetWindowCallback(@callback(), 0)
;AddKeyboardShortcut(0, #PB_Shortcut_Return, 1) ;' remove ; to capture the Key down event ???
Repeat ;' Main Loop
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
; Case #WM_KEYDOWN
; Trace("MainLoop DOWN", EventwParam())
; Case #WM_KEYUP
; Trace("MainLoop UP", EventwParam())
Case #PB_Event_Menu
AddGadgetItem (0, -1, "Event Menu Key : Return by Keyboardshortcut ")
SetGadgetState(0, CountGadgetItems(0) - 1)
EndSelect
ForEver
EndIf
EndProcedure
End main()
;' BoF
Auf ein Beispiel mit Console und RawKey() habe ich hier verzichtet, das Beispiel aus der Hilfe läuft!