You could use windows hooks, heres an example using a low-level keyboard hook that disables the left WIN key and the right WIN key as long as the hook is active.
see Windows Hooks for more info.
hook.c
Compile dll:
Hook.bmx
test.bmx
see Windows Hooks for more info.
hook.c
#include <windows.h> #define EXPORT __declspec(dllexport) static HHOOK current_hook; EXPORT DWORD keyboard_hook( int ncode, WORD wparam, KBDLLHOOKSTRUCT *lparam) { if( ncode < 0 || ncode != HC_ACTION) return CallNextHookEx( current_hook, ncode, wparam, (DWORD)lparam); if( wparam == WM_KEYDOWN || wparam == WM_SYSKEYDOWN || wparam == WM_KEYUP || wparam == WM_SYSKEYUP) { switch( lparam->vkCode) { // keys to disable case VK_LWIN: case VK_RWIN: CallNextHookEx( current_hook, ncode, wparam, (DWORD)lparam); return 1; } } return CallNextHookEx( current_hook, ncode, wparam, (DWORD)lparam); } EXPORT int init_hook( HHOOK hook) { if(hook) { current_hook = hook; return TRUE; } return FALSE; }
Compile dll:
gcc -shared hook.c -o hook.dll
Hook.bmx
SuperStrict Const WH_MIN:Int = -1 Const WH_MSGFILTER:Int = -1 Const WH_JOURNALRECORD:Int = 0 Const WH_JOURNALPLAYBACK:Int = 1 Const WH_KEYBOARD:Int = 2 Const WH_GETMESSAGE:Int = 3 Const WH_CALLWNDPROC:Int = 4 Const WH_CBT:Int = 5 Const WH_SYSMSGFILTER:Int = 6 Const WH_MOUSE:Int = 7 Const WH_HARDWARE:Int = 8 Const WH_DEBUG:Int = 9 Const WH_SHELL:Int = 10 Const WH_FOREGROUNDIDLE:Int = 11 Const WH_CALLWNDPROCRET:Int = 12 Const WH_KEYBOARD_LL:Int = 13 Const WH_MOUSE_LL:Int = 14 Const WH_MAX:Int = 14 Const WH_MINHOOK:Int = WH_MIN Const WH_MAXHOOK:Int = WH_MAX Const INIT_HOOK_NAME:String = "init_hook" Global IsHookLoaded:Int Global IsHooked:Int Private Global Handle:Int Global InitHookProc:Int( hook:Int) Global HookProc:Byte Ptr Global CurrentHook:Int Extern "Win32" Function LoadLibrary:Int( name$z) = "LoadLibraryA@4" Function GetProcAddress:Byte Ptr( handle:Int, name$z) Function FreeLibrary:Int( handle:Int) Function SetWindowsHookEx:Int( hooktype:Int, hookproc:Byte Ptr, handle:Int, param:Int) = "SetWindowsHookExA@16" Function UnhookWindowsHookEx:Int( hook:Int) EndExtern Function on_end_hook() FreeHook() EndFunction OnEnd on_end_hook Public Function LoadHook:Int( hookdll:String) FreeHook() Handle = LoadLibrary( hookdll) If Handle = 0 Then Return False InitHookProc = GetProcAddress( Handle, INIT_HOOK_NAME) If Not InitHookProc Then FreeLibrary( Handle) Return False EndIf IsHookLoaded = True Return True EndFunction Function InitHook:Int( hooktype:Int, hookname:String) If Not IsHookLoaded Then Return False ReleaseHook() HookProc = GetProcAddress( Handle, hookname) If HookProc Then CurrentHook = SetWindowsHookEx( hooktype, HookProc, Handle, 0) If CurrentHook <> 0 Then IsHooked = InitHookproc( CurrentHook) Return IsHooked EndIf EndIf Return False EndFunction Function ReleaseHook:Int() If Not IsHookLoaded Or Not IsHooked Then Return False UnhookWindowsHookEx( CurrentHook) IsHooked = False Return True EndFunction Function FreeHook:Int() If Not IsHookLoaded Then Return False ReleaseHook() FreeLibrary( Handle) IsHookLoaded = False Return True EndFunction
test.bmx
SuperStrict Import "Hook.bmx" If LoadHook( "hook.dll") Then Print "Hook is loaded." If InitHook( WH_KEYBOARD_LL, "keyboard_hook") Then Notify "Hook is active, waiting for termination" Else Print "error:InitHook() failed" EndIf Else Print "error:LoadHook() failed" EndIf FreeHook()