Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've got a simple AHK script:

#n::Run notepad.exe

If I'm looking at the desktop and hit Win+N, I see Notepad. The problem is, if I'm on looking at the Start screen and hit Win+N, I get nothing. Notepad opens on the desktop, but doesn't take me to the desktop to see it.

Is that normal behavior? Is there some fancy way to get me to the desktop if I'm currently not already there? Maybe seeing if the active window is ImmersiveLauncher, press the Start key? AutoHotkey can do that, right?

Edit 1: I got the logic down, but I quickly realized that the Start key doesn't always take you to the desktop. From an app, it takes you to the Start screen, and from the Start screen, it takes you to the last app you used.

Win8Fix()
{
    WinGetClass, class,  A
    if class = ImmersiveLauncher
        Send, {LWin down}{LWin up}
}

#n::
Win8Fix()
Run notepad.exe

Instead of Send, {LWin down}{LWin up}, I tried to get creative and press Win+B which focuses on the system tray, but I couldn't get that working from AHK:

if class = ImmersiveLauncher
    Send, {LWin down}{b down}{LWin up}

It works in desktop mode, but does nothing in Metro.

share|improve this question

2 Answers 2

#n::
{
    Run notepad.exe
        WinActivate, Program Manager
}
share|improve this answer
    
Indent by four spaces for a code block. Or select it and press ctrl + k. See editing help. –  Bob Dec 16 '12 at 8:25
    
Oh, and welcome to Super User! –  Bob Dec 16 '12 at 11:40
up vote 0 down vote accepted

This appears to work, got it from the AHK forums-

Win8Fix(ByRef pid)
{
    WinWait ahk_pid %pid%,,5

    if !ErrorLevel ; Didn't time out.
    {
        WinActivate
    }
}

#n::
Run notepad.exe,,,pid
Win8Fix(pid)
return

Doesn't work very well for running urls like #g::Run www.google.com,,,pid unfortunately, but you can still target a browser's executable and pass www.google.com as an argument.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.