KeyDown for arrows
-
you have to override the
IsInputKey
method, so that it returns true with the key arrows.protected override bool IsInputKey(Keys key)
{
if (key.KeyCode == Keys.Up) return true;
else if (key.KeyCode == Keys.Down) return true;
else if (key.KeyCode == Keys.Left) return true;
else if (key.KeyCode == Keys.Right) return true;
else return base.IsInputKey(key);
}Another Post by NnamdiOnyeyiri l Website
-
you have to override the
IsInputKey
method, so that it returns true with the key arrows.protected override bool IsInputKey(Keys key)
{
if (key.KeyCode == Keys.Up) return true;
else if (key.KeyCode == Keys.Down) return true;
else if (key.KeyCode == Keys.Left) return true;
else if (key.KeyCode == Keys.Right) return true;
else return base.IsInputKey(key);
}Another Post by NnamdiOnyeyiri l Website
-
I tried that, but when I put a breakpoint there, I see the function never gets called... hmm?
hmmm, it should do, it does when i create controls, are you creating a control from scratch? or adapting a current one? Another Post by NnamdiOnyeyiri l Website
-
To override the form or custom controls
protected override bool ProcessKeyPreview( ref System.Windows.Forms.Message mes ) { Keys keyCode = (Keys)(int)mes.WParam & Keys.KeyCode; if((mes.Msg == WM_KEYDOWN || mes.Msg == WM_KEYUP) && keyCode == Keys.Down ) { MessageBox.Show("Arrow handled"); return true; } else return false; }
for other controls like a textboxForm1_Load() this.myControl.KeyDown += new KeyEventHandler(this.MyKeyDownEvent); ... private void MyKeyDownEvent( object sender, KeyEventArgs e ) { if ( e.KeyCode == Keys.A ) MessageBox.SHow("Hey you typed an AS"); }
there you go dude the above works for override the message loop for custom controls and the below works for controls inside your container. nick I'm not an expert yet, but I play one at work. Yeah and here too. -
Downt forget the defines, I dont know where they exist in c# so i just make them consts private const int WM_KEYDOWN 0x100; private const int WM_KEYUP 0x101; your C++ include files have all the values inside the libraries. nick I'm not an expert yet, but I play one at work. Yeah and here too.