It can be obtained by overriding the ProcessCommandKey method. Here's an
example (note that I created a separate class to hold WinAPI constants):
/// <summary>
/// KeyDown Event handler which handles control keys as well as regular
/// </summary>
/// <param name="msg"><c>System.Windows.Forms.Message</c></param>
/// <param name="keyData">Key Data</param>
/// <returns>True if handled; false if not</returns>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (!toolPageNumber.Focused && !toolDocumentName.Focused && msg.Msg ==
WinUserApi.WM_KEYDOWN)
{
switch ((int)msg.WParam)
{
case WinUserApi.VK_UP:
if (pagePanel.SelectedElements.Count == 0)
{
if (!InputEnabled) return true;
if (vertScroll.Visible)
ScrollVertical(Math.Max(vertScroll.Value - vertScroll.SmallChange,
0));
return true;
}
else
{
if (!InputEnabled && pagePanel.CurrentPage == 0) return true;
pagePanel.MoveCurrentPrintElementBy(0, -1);
}
break;
case WinUserApi.VK_DOWN:
if (pagePanel.SelectedElements.Count == 0)
{
if (!InputEnabled) return true;
if (vertScroll.Visible)
ScrollVertical(Math.Min(vertScroll.Value + vertScroll.SmallChange,
_MaxNegativeVerticalSpace));
return true;
}
else
{
if (!InputEnabled && pagePanel.CurrentPage == 0) return true;
pagePanel.MoveCurrentPrintElementBy(0, 1);
}
break;
case WinUserApi.VK_LEFT:
if (pagePanel.SelectedElements.Count == 0)
{
if (!InputEnabled) return true;
if (horizScroll.Visible)
ScrollHorizontal(horizScroll.Value - horizScroll.SmallChange);
return true;
}
else
{
if (!InputEnabled && pagePanel.CurrentPage == 0) return true;
pagePanel.MoveCurrentPrintElementBy(-1, 0);
}
break;
case WinUserApi.VK_RIGHT:
if (pagePanel.SelectedElements.Count == 0)
{
if (!InputEnabled) return true;
if (horizScroll.Visible)
ScrollHorizontal(horizScroll.Value + horizScroll.SmallChange);
return true;
}
else
{
if (!InputEnabled && pagePanel.CurrentPage == 0) return true;
pagePanel.MoveCurrentPrintElementBy(1, 0);
}
break;
case WinUserApi.VK_PRIOR:
if (!InputEnabled) return true;
if (pagePanel.SelectedElements.Count == 0)
{
if (vertScroll.Visible)
ScrollVertical(Math.Max(vertScroll.Value - vertScroll.LargeChange,
0));
return true;
}
else
pagePanel.MoveCurrentPrintElementBy(0, -20);
break;
case WinUserApi.VK_NEXT:
if (!InputEnabled) return true;
if (pagePanel.SelectedElements.Count == 0)
{
if (vertScroll.Visible)
ScrollVertical(Math.Min(vertScroll.Value + vertScroll.LargeChange,
_MaxNegativeVerticalSpace));
return true;
}
else
pagePanel.MoveCurrentPrintElementBy(0, 20);
break;
case WinUserApi.VK_DELETE:
if (!InputEnabled) return true;
pagePanel.DeleteCurrentElement();
return true;
case WinUserApi.VK_CONTROL:
pagePanel.HandleElementMouseEvents = false;
break;
case WinUserApi.VK_TAB:
pagePanel.HandleElementMouseEvents = false;
if (!InputEnabled || pagePanel.HandleElementMouseEvents) return true;
if (pagePanel.PrintElements.HighestZIndex == -1) return true;
int i = pagePanel.PrintElements.IndexOfZ(_CurrentZIndex);
if (i == -1) i = 0;
if (pagePanel.ShiftOn) i = (i == 0 ?
pagePanel.PrintElements.HighestZIndex : i - 1);
else i = (i == pagePanel.PrintElements.HighestZIndex ? 0 : i + 1);
if (i == -1) return false;
pagePanel.CurrentPrintElement = pagePanel.PrintElements[i];
if (pagePanel.CurrentPrintElement != null)
{
pagePanel.CurrentPrintElement.ShowToolTip();
ShowStatusMessage("PrintElements[" + i.ToString() +
"] (" + pagePanel.PrintElements[i].ToString() +
") " + pagePanel.CurrentPrintElement.Location.ToString()) ;
}
return true;
case WinUserApi.VK_SHIFT:
pagePanel.ShiftOn = true;
break;
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
"Ciaran O''Donnell" <Ci************@discussions.microsoft.comwrote in
message news:FC**********************************@microsof t.com...
This isn't possible in .NET as far as I'm aware, you will need to hook
into
the Windows API to handle the keypress events at a far lower level as .NET
treats the ALT key as a modifier only.
There is an article about hooking in but for a different reason here (but
it
should be adaptable):
http://www.codeproject.com/useritems/CSLLKeyboard.asp
Ciaran O'Donnell
""Andrés G. Aragoneses [ knocte ]"" wrote:
>Hello. I am trying to catch the ALT key (but not as a modifier, but as a
single key clicked) on a Console application, but neither Read(),
ReadLine() nor ReadKey() catch it, how can I do it using the
System.Console class?
Thanks in advance.
Regards.
Andrés [ knocte ]
--