Pascal 如何在OnKeyUp事件中验证按键
我有很多行来检查edit1.text字段的键入内容,但我需要使用OnKeyUp事件(出于某些原因),因此如何将此代码“翻译”为Key:Word类型(通常是OnKeyPress上的Key:Char) 使用Ord(键)将键盘键的字值转换为字符值。否则,如果可用,请使用VK_u值 在您的代码片段中,您将字符('0'…'9')与值(#08)混合在一起,我不确定您是否需要测试它。如果没有,则需要在另一个比较中直接检查(#08)键或Chr(键) 此外,最好使用VK_UNKNOWN而不是#0 这是我在Lazarus中编写的一些工作代码中使用的一个KeyUp事件。嗯Pascal 如何在OnKeyUp事件中验证按键,pascal,lazarus,Pascal,Lazarus,我有很多行来检查edit1.text字段的键入内容,但我需要使用OnKeyUp事件(出于某些原因),因此如何将此代码“翻译”为Key:Word类型(通常是OnKeyPress上的Key:Char) 使用Ord(键)将键盘键的字值转换为字符值。否则,如果可用,请使用VK_u值 在您的代码片段中,您将字符('0'…'9')与值(#08)混合在一起,我不确定您是否需要测试它。如果没有,则需要在另一个比较中直接检查(#08)键或Chr(键) 此外,最好使用VK_UNKNOWN而不是#0 这是我在Laza
procedure TfrmMain.lbCmdLinesKeyUp( Sender : TObject; var Key : Word; Shift : TShiftState );
begin
if ( Key = vk_return ) and ( lbCmdLines.ItemIndex > -1 ) then
begin
if ( Shift = [ ssCtrl ] ) then
begin
if btnLineEdit.Enabled then
btnLineEdit.Click;
end
else
begin
if btnRun.Enabled then
btnRun.Click;
end;
end;
if ( Key = Ord( 'C' ) ) or ( Key = Ord( 'c' ) ) then
begin
if Shift = [ ssCtrl ] then
actCopyClipCmdLine.Execute;
//order, apparently, doesn't matter, both work
//if Shift = [ ssCtrl, ssShift ] then
if Shift = [ ssShift, ssCtrl ] then
mniCopyCLListClipClick( Self );
//if ( ssCtrl in Shift ) and ( ssShift in Shift ) and ( ssAlt in Shift ) then
if Shift = [ ssCtrl, ssShift, ssAlt ] then
actCopyCmdLine.Execute;
end;
end;
这看起来完全错了,只有当钥匙放下时,才需要做出决定。试着打字。
procedure TfrmMain.lbCmdLinesKeyUp( Sender : TObject; var Key : Word; Shift : TShiftState );
begin
if ( Key = vk_return ) and ( lbCmdLines.ItemIndex > -1 ) then
begin
if ( Shift = [ ssCtrl ] ) then
begin
if btnLineEdit.Enabled then
btnLineEdit.Click;
end
else
begin
if btnRun.Enabled then
btnRun.Click;
end;
end;
if ( Key = Ord( 'C' ) ) or ( Key = Ord( 'c' ) ) then
begin
if Shift = [ ssCtrl ] then
actCopyClipCmdLine.Execute;
//order, apparently, doesn't matter, both work
//if Shift = [ ssCtrl, ssShift ] then
if Shift = [ ssShift, ssCtrl ] then
mniCopyCLListClipClick( Self );
//if ( ssCtrl in Shift ) and ( ssShift in Shift ) and ( ssAlt in Shift ) then
if Shift = [ ssCtrl, ssShift, ssAlt ] then
actCopyCmdLine.Execute;
end;
end;