[Win32] Windowstasten sperren
Übersicht

ChristianKBetreff: [Win32] Windowstasten sperren |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Mit den der Funktion LockWinKeys lässt sich die linke und/oder rechte Windowstaste sperren. Dafür wird ein Windows-Hook verwendet, der bei jedem Tastendruck aufgerufen wird. Dann wird überprüft, ob es sich um eine Windowstaste handelt und wenn dies der Fall ist, wird die Auswertung des Tastendrucks durch Windows gestoppt -> die Taste wird blockiert.
Ich habe den Code in zwei Teile aufgeteilt, um ihn übersichtlicher zu machen. 1. Die Include-Datei Code: [AUSKLAPPEN] ' --- Funktionen ---
?win32 Extern "win32" Function SetWindowsHookExA:Int( id:Int, hookproc:Int( code:Int, wparam:Int, lparam:Int ), instance:Int, thread:Int ) Function UnhookWindowsHookEx:Int( hook:Int ) Function CallNextHookEx:Int( hook:Int, code:Int, wparam:Int, lparam:Int ) End Extern ' Globale variablen, bitte nicht verändern ;) Global wkhook:Int Global lwin:Int, rwin:Int Const WH_KEYBOARD_LL:Int = 13 ' Die Hook-Funktion, die bei jedem Tastendruck von Windows aufgerufen wird Function KeyboardProc:Int( code:Int, wparam:Int, lparam:Int ) If( code <= 0 ) CallNextHookEx( wkhook, code, wparam, lparam ) ' Herausfinden, welche Taste gedrückt wurde Local key:Int = Byte Ptr( lparam )[0] If wparam = WM_KEYDOWN Or wparam = WM_KEYUP If( ( lwin And key = $5b ) Or ( rwin And key = $05c ) ) Return 1 End If Return CallNextHookEx( wkhook, code, wparam, lparam ) End Function ? ' Funktion zum Ein-/Ausschalten des Hooks. Vor dem Beenden sollte EnableKeyLock( False ) aufgerufen werden. Function EnableKeyLock( enable:Int ) ?win32 If enable wkhook = SetWindowsHookExA( 13, KeyboardProc, GetModuleHandleA( 0 ), 0 ) Else UnhookWindowsHookEx( wkhook ) ? End Function ' Sperrt die linke oder rechte Windowstaste Function LockWinKeys( leftkey:Int, rightkey:Int ) lwin = leftkey rwin = rightkey End Function 2. Das Beispiel ( es wird vorrausgesetzt, dass die Include-Datei mit dem Namen "lockwinkeys.bmx" vorhanden ist ) Code: [AUSKLAPPEN] ' --- Beispiel ---
Framework brl.d3d7max2d Import pub.win32 SuperStrict Include "lockwinkeys.bmx" Graphics 660, 220, 0 ' Hook aktivieren EnableKeyLock( True ) Local s1:Int, s2:Int While Not( KeyDown( KEY_ESCAPE ) Or AppTerminate( ) ) Cls If KeyHit( KEY_1 ) s1 = 1 - s1 ' Tasten sperren LockWinKeys( s1, s2 ) End If If KeyHit( KEY_2 ) s2 = 1 - s2 ' Tasten sperren LockWinKeys( s1, s2 ) End If DrawText( "--- Dieses Programm sperrt die Windowstasten ( made by Christian Klaussner ) ---", 10, 10 ) DrawText( "Druecke die Tasten '1' und '2', um den Status zu wechseln.", 10, 70 ) DrawText( "Null steht fuer normal, eins fuer gesperrt.", 10, 100 ) DrawText( "Status der linken Taste: " + s1, 10, 150 ) DrawText( "Status der rechten Taste: " + s2, 10, 180 ) Flip Wend ' Hook deaktivieren EnableKeyLock( False ) ' Programm beenden End |
||
AdvanceLcd
Intel Core 2 Duo 3.2 GHz, 4 GB RAM, GeForce 8800 GTX | MacBook Pro 15,4″ Intel Core 2 Duo 2.4 GHz, 2 GB RAM, GeForce 8600M GT |
#ReaperNewsposter |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Btw: In sofern doppelpost ![]() Danke, sehr nützlich für mein aktuelles Projekt ![]() Und für andere sicherlich auch, da man ja auch andere Tasten abfragen kann ![]() PS: *rofl* Damit kann man ja auch alle Tasten sperren, ist ja besser als BlockInput() ^^ |
||
AMD Athlon 64 3500+, ATI AX800 Pro/TD, 2048 MB DRR 400 von Infineon, ♥RIP♥ (2005 - Juli 2015 -> sic!)
Blitz3D, BlitzMax, MaxGUI, Monkey X; Win7 |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group