Entwickler-Ecke

WinForms - Globaler KeyHook ALT/SHIFT/CTRL - Kombinationen


ShadowKnight - Fr 11.12.09 18:24
Titel: Globaler KeyHook ALT/SHIFT/CTRL - Kombinationen
Hallo.

Ich verwende folgende Global-Key-Hook Dll: http://www.codeproject.com/KB/cs/globalhook.aspx

Diese funktioniert soweit auch, doch wenn ich tastenkombinationen wie ctrl+A abfragen will funktioniert es nichtmehr!


C#-Quelltext
1:
2:
3:
4:
5:
if (e.Control)
{
   if (e.KeyCode == Keys.A)
      MessageBox.Show("CTRL + A pressed");
}


Bei nem normalen form_Keydown funzt das, jedoch nicht mit diesem Globalhook. Habs auch schon mit e.Modifiers.ToString().Contains("Alt"), usw. probiert. Weiss jemand eine andere Lösung?

Danke

ShadowKnight


Greenberet - Fr 11.12.09 19:26

Lies doch mal den Beitrag den du verlinkst...

Zitat:
Question

How do I catch key combinations like Ctrl+Shift+A?
Answer

You'll have to track which keys have gone down but not up. Only the most recently pressed key keeps sending KeyDown messages, but the others will still send a KeyUp when released. So if you make three flags IsCtrlDown, IsShiftDown, and IsADown, and set them to true at KeyDown and false at KeyUp, the expression (IsCtrlDown && IsShiftDown && IsADown) will give you the required result.


ShadowKnight - Sa 12.12.09 15:54

Edit2: Geht doch nicht, KeyEventArgs erkennt ALT/SHIFT/STRG einfach nicht. Woran liegt das?
Edit3: Okay geht mit e.KeyCode.ToString()... muss man erst bei allen nichtfunktionierenden keys aufschreiben.