In my application I allow the user to scroll a movie by holding down the Right arrow key by using ProcessCmdKey
. Now I would like to give the user the ability to increase the scrolling speed whenever desired. Ideally the user should be able to hold down the Right arrow key, then when he decides to increase the speed he should, without releasing the Right arrow key, hold down also the Shift key and when he decides to go back to the normal speed he should simply release back the Shift key. So the difference in the scrolling speed should be given only from Shift key modifier that should be added or removed to the Right arrow key pressure.
I tried a code like this but with no success (I've a simple label in my form in this test example):
int count = 0;
bool keyRightDown = false;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Right)
{
keyRightDown = true;
count++;
label.Text = "count = " + count.ToString();
return true;
}
if (keyData == (Keys.Shift | Keys.ShiftKey) && keyRightDown)
{
count += 10;
label.Text = "count = " + count.ToString();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override bool ProcessKeyMessage(ref Message m)
{
if ((Keys)m.WParam == Keys.Right)
{
if (m.Msg == 0x101) // KEYUP
{
keyDown = false;
return true;
}
}
return base.ProcessKeyMessage(ref m);
}
When the user add the Shift key to the Right arrow the keyData
does not contain (Keys.Shift | Keys.Right)
as I was expecting but (Keys.Shift | Keys.ShiftKey)
. However this issue can still be solved by the boolean keyRightDown
. The main problem is that when the user release back the Shift key by having at this point only the Right arrow pressed, no other calls to neither ProcessCmdKey
nor ProcessKeyMessage
are triggered. How can I achieve my goal?