开发者

c# capture Ctrl+PageUp keystroke

开发者 https://www.devze.com 2022-12-24 19:00 出处:网络
I am having trouble capturing Ctrl+PageUp keystroke in a ListView control in WinForm开发者_运维技巧s application.

I am having trouble capturing Ctrl+PageUp keystroke in a ListView control in WinForm开发者_运维技巧s 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.


No need for WndProc:

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


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");
  }


check for

Keys.Control | Keys.PageUp
0

精彩评论

暂无评论...
验证码 换一张
取 消