AutoHotkey Community

It is currently May 26th, 2012, 1:06 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Quick Launch like Vista
PostPosted: March 19th, 2007, 3:06 pm 
Offline

Joined: March 19th, 2007, 2:36 pm
Posts: 15
Windows Vista adds shortcuts for each icon on the Quick Launch Toolbar (Win+1, Win+2, etc. in icon order). See this Lifehacker article:
http://lifehacker.com/software/windows-vista/windows-vista-tip--builtin-quick-launch-keyboard-shortcuts-229787.php

EDIT: Version 2.0 released. Scroll down to see the posting.
(It's considerably more complicated than this first version, so I'm leaving v1.0 here for non-XP users.)

Seemed like a logical thing to do, so I wrote a quick ahk script that will work on any flavor of Windows:
Code:
#1::Send #{tab}{tab}{enter}
#2::Send #{tab}{tab}{right}{enter}
#3::Send #{tab}{tab}{right 2}{enter}
#4::Send #{tab}{tab}{right 3}{enter}
#5::Send #{tab}{tab}{right 4}{enter}
#6::Send #{tab}{tab}{right 5}{enter}
#7::Send #{tab}{tab}{right 6}{enter}
#8::Send #{tab}{tab}{right 7}{enter}
#9::Send #{tab}{tab}{right 8}{enter}

This assumes that the quicklaunch is the left-most toolbar (next to the start button), enabled, & all the buttons are visible, so YMMV. It's this way by default on most users systems, so I didn't bother to add this checking. Enjoy.


Last edited by bobbo on March 23rd, 2007, 3:59 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2007, 3:34 pm 
Offline

Joined: March 19th, 2006, 5:52 am
Posts: 419
Windows 2000 Pro
Works just like you described, but with the tray menu, not quick launch.

Also, the following alteration changed it to programs in the task bar. Not sure why it differs, just letting you know.
Code:
#1::Send #{tab 2}{enter}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2007, 4:13 pm 
Offline

Joined: March 19th, 2007, 2:36 pm
Posts: 15
It's simply sending a sequence of keys to get to the icon. Here's the order:

1. win-tab selects the taskbar
2. tab selects the first toolbar
3. arrow keys select the icon
4. enter executes the icon

So if your toolbars are in a different order/location, tweak the number of tabs in step 2. And if you have your icons vertically stacked, tweak the arrow keys in step 3.

A more robust solution would look like this:

1. WinActivate taskbar
2. WinGetText to determine quicklaunch control name (e.g. ToolbarWindow323), then ControlFocus to active it
3. ImageSearch to find the button in order
4. Run the found shortcut

Any volunteers to code this? The simple solution I originally posted works well enough for me.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2007, 4:30 pm 
Offline

Joined: March 19th, 2006, 5:52 am
Posts: 419
Hmmm. My Win+Tab selects the Taskbar. Then tabs from there move to the next thing to the right. Which in my case is the Tray Menu, since my Quick launch is all the way to the left next to the start button.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2007, 5:50 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Try Shift-Tab then.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Version 2.0
PostPosted: March 23rd, 2007, 2:31 pm 
Offline

Joined: March 19th, 2007, 2:36 pm
Posts: 15
OK, so I went ahead and coded that more robust version. This uses Windows API commands (SendMessage, PostMessage, DLLCall) to find the Quick Launch toolbar, find the desired button, then execute it.

EDIT: This only works on XP, Win2k apparently uses a whole different taskbar structure.
(see http://w-shadow.com/blog/2006/10/01/manipulating-taskbar-buttons/)

Code:
; Quick Launch using Win+Number Hotkey (like Windows Vista)
; v2.0
;
; AutoHotkey Version: 1.0.46.09 (tested version)
; Language:       English
; Platform:       Win9x/NT
; Author:         Bobbo
;
; Script Function:
;   Added win+num(0:9) as shortcut keys to whatever is in your quicklaunch toolbar
;   (just like Windows Vista)
;

#NoEnv
SendMode Input

#1::WinNumQL(1)
#2::WinNumQL(2)
#3::WinNumQL(3)
#4::WinNumQL(4)
#5::WinNumQL(5)
#6::WinNumQL(6)
#7::WinNumQL(7)
#8::WinNumQL(8)
#9::WinNumQL(9)

WinNumQL(button_num)
{
   ; do nothing if toolbar not loaded
   WinGetText, text, ahk_class Shell_TrayWnd
   if (InStr(text, "Quick Launch") = 0)
      return

   ; find the control name of the Quick Launch toolbar
   Loop,9
   {   
      ControlGetText,text2,ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
      IfInString,text2,Quick Launch
      {
         qlname = ToolbarWindow32%A_Index%
         break
      }
   }

   ; do nothing if not enough buttons
   SendMessage, 0x418, 0, 0, %qlname%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
   if (ErrorLevel<button_num)
      return

   ; get info about the requested button
   WinGet, pid, PID, ahk_class Shell_TrayWnd
   hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pid)
   pRB := DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 20, "Uint", 0x1000, "Uint", 0x4)
   VarSetCapacity(btn, 20)
   VarSetCapacity(nfo, 24)
   SendMessage, 0x417, button_num-1, pRB, %qlname%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pRB, "Uint", &btn, "Uint", 20, "Uint", 0)
      iBitmap := DecodeInteger(&btn + 0)
      idn     := DecodeInteger(&btn + 4)
      dwData  := DecodeInteger(&btn +12)
      iString := DecodeInteger(&btn +16)
   DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "Uint", &nfo, "Uint", 24, "Uint", 0)
      hWnd  := DecodeInteger(&nfo + 0)
      uID   := DecodeInteger(&nfo + 4)
      nMsg  := DecodeInteger(&nfo + 8)
      hIcon := DecodeInteger(&nfo +20)

   ; execute the button
   ControlGet,qlhandle,Hwnd,,%qlname%, ahk_class Shell_TrayWnd
   PostMessage, 0x111, idn, qlhandle, %qlname%, ahk_class Shell_TrayWnd  ; WM_COMMAND
   return
}

DecodeInteger(ptr)
{
   Return *ptr | *++ptr << 8 | *++ptr << 16 | *++ptr << 24
}

EncodeInteger(ref, val, nSize = 1)
{
   DllCall("ntdll\RtlFillMemoryUlong", "Uint", ref, "Uint", nSize * 4, "Uint", val)
}


Theoretically this should be more reliable than the first version, because it doesn't rely on windows shortcut keys & moving the cursor focus.

Thanks to Sean (http://www.autohotkey.com/forum/viewtopic.php?t=17314) for his code for extracting button info.

Also check out how I execute the button using WM_COMMAND: it looks simple, but it took me a lot of googling to figure it out. You can use this method to execute any toolbar button in any application without using screen coordinates and simulated mouse clicks. This is especially important if only part of the menu is visible on the screen (e.g. some of your buttons are only accessible by a drop-down menu, because the toolbar is too short to display them all.).


Report this post
Top
 Profile  
Reply with quote  
 Post subject: #1 ejects CD!
PostPosted: July 29th, 2008, 1:34 am 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
Hi I have been using your script and I like it.

For some reason Win+1 opens the CD drive. :shock: All other quick launches work as expected.

Has anyone else found this?

(I am using the complicated XP only version)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: scritps
PostPosted: January 6th, 2009, 9:20 pm 
what application are you useing to compile and run this script?


Report this post
Top
  
Reply with quote  
 Post subject: awesome works for me
PostPosted: June 22nd, 2009, 2:27 am 
great, works for me, thanks


Report this post
Top
  
Reply with quote  
PostPosted: June 22nd, 2009, 2:31 am 
thanks, exactly what I was looking for :-)

Before the upgrade, I was doing it hard-coded:
Code:
;#1::Run "C:\Documents and Settings\HP_Administrator\Local Settings\Application Data\Google\Chrome\Application\chrome.exe"
;#2::Run "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE"  /recycle
;#4::Run "%SystemRoot%\system32\mstsc.exe"

... etc

But your version is better

I also appreciate that you posted the old version too, since the less-robust version is very few lines of code... Though I am using the newer version.

http://www.mepem.com/pemtech


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2010, 2:23 pm 
Offline

Joined: February 6th, 2005, 10:40 pm
Posts: 26
can someone modify this script so that instead of launching another instance of an application, the win+# hotkey activates an existing instance of the application?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2010, 4:03 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
Why not doing it by yourself? Youre a forum member since 2005, so this should be no problem for you.
chessonly wrote:
can someone modify this script so that instead of launching another instance of an application, the win+# hotkey activates an existing instance of the application?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2010, 5:49 pm 
Offline

Joined: February 6th, 2005, 10:40 pm
Posts: 26
^Fair enough. i guess i could try.. almost everything in the script is greek to me though. could give it a try


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2010, 6:48 pm 
Offline

Joined: February 6th, 2005, 10:40 pm
Posts: 26
OK i gave it a shot.
Code:
if WinExist("ahk_class classname")
{
WinActivate
}
else
{
;execute code
}

now only 'classname' needs to be replaced by the classname of the quick launch button.
but how to find it , without opening the application ?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: DataLife, IsNull and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group