Sign in to follow this  
Followers 0
BeBoP

Capturing the left Windows key to replace it's function.

1 post in this topic

#1 ·  Posted (edited)

Hi, recently I moved to Windows 8 and while I do like it there is a small annoyance. The taskbar is hidden while the Start Screen is up, to remedy this I wrote a script that re-sizes the Start Screen to show the taskbar.

However I ran into an issue, certain applications will hide the taskbar forcing me to reactive it. In order to get around this I have to stop the Windows key from bringing up the Start Screen then I have to active the taskbar and then finally bring up the Start Screen, otherwise activating the taskbar will close the Start Menu if it was already brought up by the Windows key.

While I have a working script that already does this I feel the way its done is overkill. Currently my script hooks the entire keyboard and only looks for the Windows key to change its usage. I'm worried that having a script constantly hooked into the keyboard just to slightly move a window is unnecessary and might cause problem for other programs which might need to use the keyboard. Are my fears wrong? Is there a better way to hook the Windows key or maybe a better way to get around this problem?

I should mention that I have looked into blocking the key and I have tried the HotKeySetEx() library but neither of those work for the purpose of this script. Thanks for reading sorry for the wall of text.

TL;DL, wrote a script to show the taskbar while Windows 8 Start screen is open ran into some problems. Need a better way to hook the Windows key other than hooking the entire keyboard.

#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("WinTitleMatchMode", 4)

HotKeySet("{F4}", "close")

Global $sHexKeys, $sMouse, $sString, $hHookKeyboard, $pStub_KeyProc, $toggle, $activeWindow

$pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr")
$hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0)

$startMenu = _WinAPI_FindWindow("ImmersiveLauncher", "Start menu")
$taskBar = _WinAPI_FindWindow("Shell_TrayWnd", "")

While 1
    Sleep(23)
    $taskBarPos = WinGetPos($taskBar)
    If $taskBarPos[1] >= (@DesktopHeight - 3) Then
        WinMove($startMenu, "", 0, 0, @DesktopWidth, $taskBarPos[1], 0)
    Else
        WinMove($startMenu, "", 0, 0, @DesktopWidth, $taskBarPos[1] + 2, 0)
    EndIf
WEnd

Func taskbarHandler($mode = 1)
    Local $inApp = Not (_WinAPI_GetClassName(WinGetHandle("[active]")) <> "Windows.UI.Core.CoreWindow")
    Local $startMenuOpen = WinActive($startMenu)
    Local $taskBarOpen = WinActive($taskBar)
    If $startMenuOpen = 0 And $taskBarOpen = 0 And $toggle = 0 And $inApp = 0 Then
        $activeWindow = WinGetHandle("[active]", "")
        WinActivate($taskBar)
        Send("{RWIN DOWN}")
        Sleep(5)
        Send("{RWIN UP}")
        $toggle = 1
    EndIf
    If $startMenuOpen And $taskBarOpen = 0 And $toggle = 0 And $inApp = 0 Then
        If $activeWindow <> -1 And $activeWindow <> $startMenu And $activeWindow <> $taskBar And WinExists($activeWindow) Then
            WinActivate($activeWindow)
        Else
            WinActivate($taskBar)
        EndIf
        $toggle = 1
    EndIf
    If $startMenuOpen = 0 And $taskBarOpen And $toggle = 0 And $inApp = 0 Then
        WinActivate($taskBar)
        Send("{RWIN DOWN}")
        Sleep(5)
        Send("{RWIN UP}")
        $toggle = 1
    EndIf
    If $inApp = 1 Then
        WinActivate($taskBar)
        $toggle = 1
    EndIf
    Return -1
EndFunc   ;==>taskbarHandler

Func close()
    WinMove($startMenu, "", 0, 0, 1024, 768, 0)
    Exit
EndFunc   ;==>close

Func OnAutoITExit()
    DllCallbackFree($pStub_KeyProc)
    _WinAPI_UnhookWindowsHookEx($hHookKeyboard)
EndFunc   ;==>OnAutoITExit

Func _KeyProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)
    Local $KBDLLHOOKSTRUCT = DllStructCreate("dword vkCode;dword scanCode;dword flags;dword time;ptr dwExtraInfo", $lParam)
    Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "vkCode")
    Switch $wParam
        Case 0x00000101
            If $vkCode = 0x5B Then
                taskbarHandler()
                Return -1
            EndIf
        Case 0x00000100
            If $vkCode = 0x5B Then
                $toggle = 0
                Return -1
            EndIf
    EndSwitch
    Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func _keybd_event($vkCode, $Flag)
    DllCall('user32.dll', 'int', 'keybd_event', 'int', $vkCode, 'int', 0, 'int', $Flag, 'ptr', 0)
EndFunc   ;==>_keybd_event
Edited by BeBoP

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