I want to be able to use the space key to modify the behavior of the mouse while it is held down. Without knowing better I am imagining it involves some kind of coordination between two (or three) event handler – mousemove, keydown, and keyup. But I am wondering if there is some way to handle it entirely within one event handler – mousemove.
Example code to give an idea of what I hope to be able to do…
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (Keyboard.KeyDown == Keys.Space)
{
/* Do modified behavour for left mouse being held down while
space is also held down */
}
else
{
// Do normal behavour for left mouse being held down
}
}
}
Is something like this possible or will I have to save the state of the space key to a class variable using keydown event handler and check it with the mouse move handler?
You should set a variable in your KeyDown-Event and check it in your MouseEvent: