我正在尝试通过ALT + 9检测ALT + 1的热键,但是当按下ALT时,键将作为Key.System进入。当按下CTRL + NumPad0时,它的键是Key.NumPad0,这是正确的。
private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
bool isAlt = Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt);
bool isCtrl = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);
string ctrlMod = string.Empty;
if (isAlt)
{
ctrlMod = "alt + " + e.Key.ToString();
}
if (isCtrl)
{
ctrlMod = "ctrl + " + e.Key.ToString();
}
Debug.WriteLine("Key is " + ctrlMod);
}
ALT + NumPad0到ALT + NumPad9产生:
键是alt + System
Ctrl正常工作
键是ctrl + NumPad1
键是ctrl + NumPad2
键是ctrl + NumPad3
答案 0 :(得分:1)
您可以使用SELECT
Number,
SUM(TIME_TO_SEC(TIMEDIFF(DateEnd, DateBgn))) AS Duration
FROM
calls
WHERE
UserId = 10 AND
Type = 1 # Incomming Call
GROUP BY
Number
ORDER BY
2 DESC
LIMIT 10;
和Keyboard.Modifiers
属性通过KeyEventArgs.SystemKey
检测ALT+1
:
ALT+9
private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Alt)
{
string ctrlMod = "alt + " + e.SystemKey.ToString();
Debug.WriteLine("Key is " + ctrlMod);
}
}
答案 1 :(得分:0)
我认为maccettura是正确的,它与'Windows Alt代码'有关。我可以使用
绕过它if (Keyboard.IsKeyDown(Key.NumPad0)) { }