Search code examples
c#winformslistviewkeyboardkeystroke

c# capture Ctrl+PageUp keystroke


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.


Solution

  • No need for WndProc:

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