Jump to content

KBDLLHOOKSTRUCT - Block ALT-TAB [SOLVED]


ken82m
 Share

Recommended Posts

I've been working on a custom shutdown interface and I almost have it done

I know I can't shutdown CTL+ALT+DEL nor do I want to I've set the script to exit when task manager opens.

But I do want to stop alt+tab if I can. things go a little screwy if hit it.

This is the existing code:

Func _Key_Proc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($ah_Hooks[3], $nCode, $wParam, $lParam)
    
    Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)
    Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")
    
    If StringInStr($ah_Hooks[0], "|0x" & Hex($vkCode, 2) & "|") Then Return 1
    _WinAPI_CallNextHookEx($ah_Hooks[3], $nCode, $wParam, $lParam)
EndFunc

I changed it to this:

Func _Key_Proc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($ah_Hooks[3], $nCode, $wParam, $lParam)
    
    Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)
    Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")
;Added================
    Local $flags = DllStructGetData($KBDLLHOOKSTRUCT, "flags")
    Local $scanCode = DllStructGetData($KBDLLHOOKSTRUCT, "scanCode")
;====================
    If StringInStr($ah_Hooks[0], "|0x" & Hex($vkCode, 2) & "|") Then Return 1
    _WinAPI_CallNextHookEx($ah_Hooks[3], $nCode, $wParam, $lParam)
EndFunc

Here's the result from microsoft's SPY++ tool:

<00001> 00051004 P WM_SYSKEYDOWN nVirtKey:VK_MENU cRepeat:1 ScanCode:38 fExtended:0 fAltDown:1 fRepeat:0 fUp:0

<00002> 00051004 P WM_KEYUP nVirtKey:VK_MENU cRepeat:1 ScanCode:38 fExtended:0 fAltDown:0 fRepeat:1 fUp:1

But I'm not sure how to use that informattion to return 1 under that condition here.

Thanks,

Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I tried this adding a file write line like this:

FileWriteLine("C:\key.txt", $scanCode)

I got a 15 and 56 from alt-tab

If $scanCode = 15 Then Return 1

So added this but had not effect:

If $scanCode = 56 Then Return 1

Then I tried this:

If $scanCode = 15 Then Return 1

It definitely stopped alt-tab but when the script exited alt seemed to stuck down or continuely being hit.

I couldn't type anything and if I hit the space bar it would bring up the (restore/close/maximize) menu.

I could normally get the menu by pressing and releasing alt and then hitting the space bar.

Without that line everything is fine.

Any ideas?

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I got it, did a FileWriteline for Hex($vkCode, 2)

It gave me 0xA4 and 0x09.

Blocking 0xA4 did nothing.

But blocking 0x09 did what I wanted, killed ALT-TAB, and no keys are stuck.

Although it also blocks tab by itself but I can live with that, and CTRL+ALT+DEL till works so that works for me.

Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...