 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
bobbo
Joined: 19 Mar 2007 Posts: 14
|
Posted: Mon Mar 19, 2007 3:06 pm Post subject: Quick Launch like Vista |
|
|
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 Fri Mar 23, 2007 3:59 pm; edited 2 times in total |
|
| Back to top |
|
 |
TheIrishThug
Joined: 19 Mar 2006 Posts: 370
|
Posted: Mon Mar 19, 2007 3:34 pm Post subject: |
|
|
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} |
|
|
| Back to top |
|
 |
bobbo
Joined: 19 Mar 2007 Posts: 14
|
Posted: Mon Mar 19, 2007 4:13 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
TheIrishThug
Joined: 19 Mar 2006 Posts: 370
|
Posted: Mon Mar 19, 2007 4:30 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Mon Mar 19, 2007 5:50 pm Post subject: |
|
|
| Try Shift-Tab then. |
|
| Back to top |
|
 |
bobbo
Joined: 19 Mar 2007 Posts: 14
|
Posted: Fri Mar 23, 2007 2:31 pm Post subject: Version 2.0 |
|
|
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.). |
|
| Back to top |
|
 |
supergrass
Joined: 21 Feb 2007 Posts: 29 Location: Australia
|
Posted: Tue Jul 29, 2008 1:34 am Post subject: #1 ejects CD! |
|
|
Hi I have been using your script and I like it.
For some reason Win+1 opens the CD drive. All other quick launches work as expected.
Has anyone else found this?
(I am using the complicated XP only version) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|