c# 捕获 Ctrl+PageUp 按键

发布于 2024-08-26 22:11:55 字数 489 浏览 4 评论 0原文

我在 WinForms 应用程序的 ListView 控件中捕获 Ctrl+PageUp 击键时遇到问题。

我正在使用此代码来捕获击键 -

private void ListViewEx_KeyDown(object sender, KeyEventArgs e)
{
...
if(e.Control){
if((e.KeyCode ^ Keys.Left) == 0)
    MessageBox.Show("Left"); //shows messagebox
else if((e.KeyCode ^ Keys.PageUp) == 0)
    MessageBox.Show("PageUp"); //does not
...
}

我是否需要深入 WndProc 来处理此键?谢谢。


编辑:我发现这可行,问题在于在 ListControl 到达这些键之前封闭 TabControl 处理这些键。

I am having trouble capturing Ctrl+PageUp keystroke in a ListView control in WinForms application.

I am using this code to capture keystrokes -

private void ListViewEx_KeyDown(object sender, KeyEventArgs e)
{
...
if(e.Control){
if((e.KeyCode ^ Keys.Left) == 0)
    MessageBox.Show("Left"); //shows messagebox
else if((e.KeyCode ^ Keys.PageUp) == 0)
    MessageBox.Show("PageUp"); //does not
...
}

Do I need to dive into WndProc to process this key? Thanks.


Edit: I've found out that this works, the problem was in enclosing TabControl handling these keys before ListControl got to them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不…忘初心 2024-09-02 22:11:55

不需要 WndProc:

if ((e.Modifiers & ModifierKeys) == Keys.Control && e.KeyCode == Keys.PageUp)
{
    // ctrl + page up was pressed
}

No need for WndProc:

if ((e.Modifiers & ModifierKeys) == Keys.Control && e.KeyCode == Keys.PageUp)
{
    // ctrl + page up was pressed
}
预谋 2024-09-02 22:11:55

e.KeyData 参数包括修饰键。让它看起来像这样:

  if (e.KeyData == (Keys.Control | Keys.PageDown)) {
    // Do your stuff
    Console.WriteLine("Ctrl+PgDn");
  }

The e.KeyData argument includes the modifier keys. Make it look like this:

  if (e.KeyData == (Keys.Control | Keys.PageDown)) {
    // Do your stuff
    Console.WriteLine("Ctrl+PgDn");
  }
明月夜 2024-09-02 22:11:55

检查

Keys.Control | Keys.PageUp

check for

Keys.Control | Keys.PageUp
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文