Sign in to follow this  
Followers 0
ken82m

KBDLLHOOKSTRUCT - Block ALT-TAB [SOLVED]

3 posts in this topic

#1 ·  Posted (edited)

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

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
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


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
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
Sign in to follow this  
Followers 0