Manchmal ist es besser, die Windowstaste nicht allen Benutzern zur Verfügung zu stellen. Prinzipiell funktioniert das Ganze so:
Und hier der Code: Public Class Form1 ' benötigte API-Deklarationen Private Declare Function GetAsyncKeyState Lib "user32" ( _ ByVal vKey As Integer) As Short Private Declare Sub keybd_event Lib "user32" ( _ ByVal bVk As Byte, _ ByVal bScan As Byte, _ ByVal dwFlags As Integer, _ ByVal dwExtraInfo As Integer) Const KEYEVENTF_KEYUP = &H2 Const VK_ESCAPE = &H1B Const VK_LWIN = &H5B Const VK_RWIN = &H5C ' Timer Dim WithEvents oTimer As Timer Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ' Timer-Intervall einstellen und starten oTimer = New Timer oTimer.Interval = 10 oTimer.Start() End Sub Private Sub Form1_FormClosing(ByVal sender As Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing ' Timer stoppen oTimer.Stop() End Sub Private Sub oTimer_Tick(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles oTimer.Tick If CBool(GetAsyncKeyState(VK_LWIN) And 1) Or _ CBool(GetAsyncKeyState(VK_RWIN) And 1) Then ' Wenn Windowstaste gedrückt, Escapetaste drücken... Call keybd_event(VK_ESCAPE, 0, 0, 0) ' ... und wieder loslassen Call keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0) End If End Sub End Class |