KeyDown KeyPress 难题 - 如何取消 Ctrl + Space 中的 Space
KeyDown KeyPress Conundrum - How to cancel the Space in Ctrl + Space
如果我理解正确,KeyDown 事件不能阻止字符键 (space) 被传递到控件。
但是 KeyPress 事件没有告诉我 Ctrl 键是否按下。
但我只需要取消space,如果Ctrl被按下
如果 ctrl 也按下了,我如何防止编辑控件收到 space 按键?
用途:我有一个文本框,我可以从中提出搜索建议。我想使用快捷键 ctrl+space 弹出建议。但在这种情况下,我不想将 space 添加到编辑文本中。
I have a text box, from which I am making search suggestions. I want to pop the suggestions up using the short cut ctrl+space. But in this case, I don't want to add the space to the edit text.
例如,使用附加到操作的快捷方式处理 CTRL + SPACE 输入。以这种方式处理密钥将不会到达编辑控件。
the KeyPress event doesn't tell me whether the Ctrl is down.
否,但您可以改用 Win32 GetKeyState()
函数。
How can I prevent an edit control from receiving the space keypress if the ctrl is also down?
像这样:
procedure TForm58.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (Key = ' ') and (GetKeyState(VK_CONTROL) < 0) then
begin
Key := #0;
// do something...
end;
end;
如果我理解正确,KeyDown 事件不能阻止字符键 (space) 被传递到控件。
但是 KeyPress 事件没有告诉我 Ctrl 键是否按下。
但我只需要取消space,如果Ctrl被按下
如果 ctrl 也按下了,我如何防止编辑控件收到 space 按键?
用途:我有一个文本框,我可以从中提出搜索建议。我想使用快捷键 ctrl+space 弹出建议。但在这种情况下,我不想将 space 添加到编辑文本中。
例如,I have a text box, from which I am making search suggestions. I want to pop the suggestions up using the short cut ctrl+space. But in this case, I don't want to add the space to the edit text.
使用附加到操作的快捷方式处理 CTRL + SPACE 输入。以这种方式处理密钥将不会到达编辑控件。
the KeyPress event doesn't tell me whether the Ctrl is down.
否,但您可以改用 Win32 GetKeyState()
函数。
How can I prevent an edit control from receiving the space keypress if the ctrl is also down?
像这样:
procedure TForm58.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (Key = ' ') and (GetKeyState(VK_CONTROL) < 0) then
begin
Key := #0;
// do something...
end;
end;