Hallo,
seit den Anfängen meiner Programmiererei mit XProfan habe ich nach einer Möglichkeit gesucht, die Eingabe von Tastenkombinationen zuverlässig abzufragen. Sowas wie "Ctrl-F" ist da gar nicht so trivial. Der Zeichencode in wParam von WM_CHAR oder auch WM_KEYDOWN taugt da nämlich nicht viel, weil die Ergebnisse mehrdeutig sind.
Ich habe jetzt endlich eine Möglichkeit gefunden, die tatsächlich gut zu funktionieren scheint. Außerdem ist eine PH-Datei angehängt (MoreScancode.ph), die die Scancodes von A-Z und 0-9 enthält. Die fehlen nämlich in den bei XProfan mitgelieferten PH-Dateien.
Code
$H windows.ph
$H messages.ph
$H MoreScancodes.ph 'VK_0 bis VK_9 und VK_A bis VK_Z
declare _ende%,_sc_taste$,_hE%,_ws#
SUBCLASSPROC
declare sWnd&,sMsg%,swParam&,slParam&
declare keyboardstate#,shift&,ctrl&,alt&
@Set("WinProc",1)
sWnd&=&sWnd
sMsg%=%sMessage
swParam&=&swParam
slParam&=&slParam
if sMsg%=~WM_CHAR
dim keyboardstate#,256
~GetKeyboardState(keyboardstate#)
shift&=@byte(keyboardstate#,~VK_SHIFT) & 128
ctrl&=@byte(keyboardstate#,~VK_CONTROL) & 128
'alt&=@byte(keyboardstate#,~VK_MENU) & 128 'funktioniert nur mit ~WM_KEYDOWN
'128=Taste gedrückt, 0=Taste nicht gedrückt
if (shift&=0) and (ctrl&=0) and ((@byte(keyboardstate#,~VK_RETURN) & 128)=128) 'Return
_sc_taste$="Return"
leavewaitinput
@Set("WinProc",0)
elseif (shift&=0) and (ctrl&=128) and ((@byte(keyboardstate#,~VK_RETURN) & 128)=128) 'Ctrl-Return
_sc_taste$="Ctrl-Return"
leavewaitinput
@Set("WinProc",0)
elseif (shift&=0) and (ctrl&=0) and ((@byte(keyboardstate#,~VK_A) & 128)=128) 'A
_sc_taste$="A"
leavewaitinput
@Set("WinProc",1) 'a soll natürlich bearbeitet werden (z.B. in einem Edit-Feld angezeigt werden)
elseif (shift&=128) and (ctrl&=0) and ((@byte(keyboardstate#,~VK_A) & 128)=128) 'Shift-A
_sc_taste$="Shift-A"
leavewaitinput
@Set("WinProc",1) 'A soll natürlich bearbeitet werden (z.B. in einem Edit-Feld angezeigt werden)
elseif (shift&=0) and (ctrl&=128) and ((@byte(keyboardstate#,~VK_A) & 128)=128) 'Ctrl-A
_sc_taste$="Ctrl-A"
leavewaitinput
@Set("WinProc",0)
elseif (shift&=128) and (ctrl&=128) and ((@byte(keyboardstate#,~VK_A) & 128)=128) 'Shift-Ctrl-A
_sc_taste$="Shift-Ctrl-A"
leavewaitinput
@Set("WinProc",0)
elseif (shift&=0) and (ctrl&=0) and ((@byte(keyboardstate#,~VK_ESCAPE) & 128)=128) 'Esc
_sc_taste$="Esc"
leavewaitinput
@Set("WinProc",0)
elseif (shift&=0) and (ctrl&=0) and ((@byte(keyboardstate#,~VK_TAB) & 128)=128) 'Tab
_sc_taste$="Tab"
leavewaitinput
@Set("WinProc",0)
elseif (shift&=128) and (ctrl&=0) and ((@byte(keyboardstate#,~VK_TAB) & 128)=128) 'Shift-Tab
_sc_taste$="Shift-Tab"
leavewaitinput
@Set("WinProc",0)
endif
dispose keyboardstate#
elseif sMsg%=~WM_KEYDOWN 'für die F-Tasten und für Kombinationen mit der Alt-Taste
dim keyboardstate#,256
~GetKeyboardState(keyboardstate#)
shift&=@byte(keyboardstate#,~VK_SHIFT) & 128
ctrl&=@byte(keyboardstate#,~VK_CONTROL) & 128
alt&=@byte(keyboardstate#,~VK_MENU) & 128
'128=Taste gedrückt, 0=Taste nicht gedrückt
if (shift&=0) and (ctrl&=0) and (alt&=0) and ((@byte(keyboardstate#,~VK_F1) & 128)=128) 'Ctrl-F1
_sc_taste$="F1"
leavewaitinput
@Set("WinProc",0)
'elseif (shift&=128) and (ctrl&=0) and (alt&=128) and ((@byte(keyboardstate#,~VK_A) & 128)=128) 'Shift-Alt-A - diese Kombination funktioniert nicht
' _sc_taste$="Shift-Alt-A"
' @Set("WinProc",0)
' leavewaitinput
elseif (shift&=0) and (ctrl&=128) and (alt&=128) and ((@byte(keyboardstate#,~VK_A) & 128)=128) 'Ctrl-Alt-A
_sc_taste$="Ctrl-Alt-A"
leavewaitinput
@Set("WinProc",0)
elseif (shift&=128) and (ctrl&=128) and (alt&=128) and ((@byte(keyboardstate#,~VK_A) & 128)=128) 'Shift-Ctrl-Alt-A
_sc_taste$="Shift-Ctrl-Alt-A"
leavewaitinput
@Set("WinProc",0)
endif
dispose keyboardstate#
endif
return 0
ENDPROC 'SUBCLASSPROC
PROC LeaveWaitInput
@sendmessage(%HWnd,$8000,0,0) 'usermessage senden, die nichts weiter tut, außer waitinput zu verlassen
ENDPROC
'Hauptprogramm
cls
usermessages $10,$8000
_hE%=@create("EDIT",%HWnd,"",200,10,300,20)
dim _ws#,1000
widestring _ws#,0="z.B. Return o. Tab drücken (piepst nicht)"
@sendmessage(_hE%,5377,1,_ws#) '5377=~EM_SetCueBanner; lParam: 0=Hinweis nur anzeigen, wenn das Editfeld nicht den Fokus hat (default); 1=auch anzeigen, wenn fokussiert
dispose _ws#
setfocus(_hE%)
subclass %HWnd,1
subclass _hE%,1
_ende%=0
whilenot _ende%
waitinput
if (_sc_taste$="Esc") or (%uMessage=$10)
_sc_taste$=""
_ende%=1
elseif _sc_taste$="Return"
_sc_taste$=""
print "Return"
elseif _sc_taste$="F1"
_sc_taste$=""
print "F1"
elseif _sc_taste$="Ctrl-Return"
_sc_taste$=""
print "Ctrl-Return"
elseif _sc_taste$="A"
_sc_taste$=""
print "A"
elseif _sc_taste$="Shift-A"
_sc_taste$=""
print "Shift-A"
elseif _sc_taste$="Ctrl-A"
_sc_taste$=""
print "Ctrl-A"
elseif _sc_taste$="Shift-Ctrl-A"
_sc_taste$=""
print "Shift-Ctrl-A"
elseif _sc_taste$="Shift-Alt-A"
_sc_taste$=""
print "Shift-Alt-A"
elseif _sc_taste$="Ctrl-Alt-A"
_sc_taste$=""
print "Ctrl-Alt-A"
elseif _sc_taste$="Shift-Ctrl-Alt-A"
_sc_taste$=""
print "Shift-Ctrl-Alt-A"
elseif (_sc_taste$="Tab") or (_sc_taste$="Shift-Tab")
if @getfocus(%HWnd)
@setfocus(_hE%)
else
@setfocus(%HWnd)
endif
endif
endwhile
subclass _hE%,0
subclass %HWnd,0
usermessages 0
end
Alles anzeigen