Hot/Accelerator Keys
- Posted by Wolf <wolfritz at KING.IGS.NET> May 23, 2001
- 438 views
-- demo of hiding a window, and getting it back, -- or changing colors, by pressing a hotkey combination -- originally by Eddy Van Esch, 15/01/2001 include win32lib.ew without warning constant WM_HOTKEY = #312, MOD_CTRL = #2, key = 'S', -- hotkeys are CTRL S,Z,X... change as necessary key2 = 'Z', key3 = 'X', zRegisterHotKey = registerw32Function( user32, "RegisterHotKey",{ C_LONG, C_LONG, C_LONG, C_LONG }, C_LONG ), zUnregisterHotKey = registerw32Function( user32, "UnregisterHotKey",{ C_LONG, C_LONG }, C_LONG ) atom ok sequence msg msg="Click 'Hide window' button to hide this window.\n" & "Press hotkey combination CTRL S to show the window again.\n\n" & "CTRL Z, and CTRL X change the window's colors." constant Win1 = create( Window, "HotKey Demo", 0, Default, Default,400, 200, 0 ), HideButton = create( PushButton, "Hide window", Win1,120, 12, 144, 40, 0 ), TheTxt = create( LText, msg, Win1, 40, 70, 300, 70, 0 ) -- Hide button's behavior procedure onClick_HideButton() setVisible( Win1, False ) -- Hide the window end procedure -- Event handler: intercept the hotkey and define what to do with it: procedure Events(atom iMsg, atom wparam, atom lparam) if iMsg = WM_HOTKEY then if hi_word(lparam) = 'S' then --unhide window, can be used to do anything you --want here... setVisible( Win1, True ) elsif hi_word(lparam) = 'Z' then setWindowBackColor(Win1,Yellow) setWindowBackColor(TheTxt,Yellow) elsif hi_word(lparam) = 'X' then setWindowBackColor(Win1,getSysColor(COLOR_BTNFACE)) setWindowBackColor(TheTxt,getSysColor(COLOR_BTNFACE)) end if end if end procedure procedure register_keys() -- register hotkeys ok = w32Func(zRegisterHotKey, {getHandle(Win1), 1, MOD_CTRL, key}) ok = w32Func(zRegisterHotKey, {getHandle(Win1), 2, MOD_CTRL, key2}) ok = w32Func(zRegisterHotKey, {getHandle(Win1), 3, MOD_CTRL, key3}) end procedure -- onClick[HideButton] = routine_id( "onClick_HideButton" ) onEvent[Win1] = routine_id( "Events" ) onOpen[Win1] = routine_id("register_keys") WinMain( Win1, Normal ) --normal event loop