Mega Code Archive

 
Categories / Delphi / Examples
 

Keysdisable

> I believe Jim Burns has a solution for this... Cute! And I belive you and I traded ideas on issues like this for a short while so you should have everything I have baby! It's been a while since I played with these issues including disabling Alt-Tab, Alt-Esc, the Logo keys, etc. On Win98 you can disable ALL Fast Task Switching (FTS) with the following, procedure EnableFastTaskSwitching(Enable : boolean = True); begin // Logical twist here. If Enable is False, we must use True to disable, // If Enable is True, we must use False to enable SystemParametersInfo(SPI_SCREENSAVERRUNNING, cardinal(NOT Enable), nil, 0); end; This is a blanket-trick however and it kills it everything, including HotKey sequences. To get more specific control, the only way I've found is a system keyboard hook where you test specific keys and key combinations. But again, there are some differences there even with respect to Win98 and WinNT/2K. More importantly WinNT/2K has a low-level Keyboard hook (WH_KEYBOARD_LL) that will get you inside the input queue before the standard hook. This allows you to prevent just about everything individually except Ctrl-Alt-Del. On Win98, since the hook isn't available, this means you can't prevent the use of the Logo keys this way, although you will catch their use. With repect to this low-level hook we have the following to help test, const LLKHF_EXTENDED = $00000001; const LLKHF_INJECTED = $00000010; const LLKHF_ALTDOWN = $00000020; const LLKHF_UP = $00000080; These along with the structure, type pKBDLLHookStruct = ^TKBDLLHookStruct; {$EXTERNALSYM tagKBDLLHOOKSTRUCT} tagKBDLLHOOKSTRUCT = packed record vkCode : DWORD; scanCode : DWORD; flags : DWORD; time : DWORD; dwExtraInfo : DWORD; end; TKBDLLHookStruct = tagKBDLLHOOKSTRUCT; {$EXTERNALSYM KBDLLHOOKSTRUCT} KBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT; are not defined in the standard Delphi units so you'll have to add them yourself. Inside your low-level keyboard hook procedure you can do something simple like, if (pkbhs^.vkCode = VK_CONTROL) OR (pkbhs^.vkCode = VK_ESCAPE) then begin Result := 1; end; But you'll notice this will kill ALL use of Ctrl AND Esc. Ctrl-Esc then has it's own interesting problems. The problem here is how to detect only a Ctrl-Esc combination. Given the consts you could test for a Alt-Esc combination simply like, if (pkbhs^.vkCode = VK_ESCAPE) AND (pkbhs^.flags = LLKHF_ALTDOWN) then begin Result := 1; end; That's easy to understand, but there is no, LLKHF_CTRLDOWN as one might expect. Could it be, if (pkbhs^.vkCode = VK_ESCAPE) AND (pkbhs^.flags = LLKHF_EXTENDED) then begin Result := 1; end; I don't know. I've not tried. And I've not found a detailed explaination of these constants. By their naming, my guess is this shouldn't work, but who knows? Anyone else? It's worth a try. That's pretty much as far as I got on the matter. A solution? Is there such a thing with Windows? :) Maybe someone else has some specific details on the holes in my solution or other ideas, and between us all we can patch together a picture of all our options with respect to controlling the use, individually, in select groups, or across the board, of these specialized keys and key combos on both Win98 AND WinNT/2k. Is that too much to ask? :) --------------------------------------------------------------------------- Jim Burns jimburns@technologydynamics.com Technology Dynamics http://www.technologydynamics.com Pearland, Texas 281 485-0410 / UIN #1845000 USA http://www.brainbench.com/transcript.jsp?pid=96029 --------------------------------------------------------------------------- "Delphi where we can; the API where it counts!" _______________________________________________ Delphi mailing list -> Delphi@elists.org http://www.elists.org/mailman/listinfo/delphi