Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 924
Axarydax Avatar asked Aug 29 '26 08:08

Axarydax


1 Answers

No need for WndProc:

if ((e.Modifiers & ModifierKeys) == Keys.Control && e.KeyCode == Keys.PageUp)
{
    // ctrl + page up was pressed
}
like image 149
Fredrik Mörk Avatar answered Aug 31 '26 01:08

Fredrik Mörk