开发者

Putting the focus on the tray icons in Windows XP using Python

I'm a Windows-XP-using keyboard devotee, and I want to bind Start-T to put the keyboard focus on the tray icon. (Because it'll be so much nicer than Start-B and then many Shift-Tabs.)

So I'd like to make a Python program t开发者_运维知识库hat puts the keyboard focus on the tray icons. How could I do this from Python? I know very little about controlling Windows' behavior.

If there's some ready-made program that does this, I'll be happy to hear about that too.


I am 99% sure that there is no supported way to access the tray notification area. The actually focusable element is the overflow button, not the tray icon itself - and the Windows Shell team doesn't want to guarantee that this button will always be focusable or even that this button will exist in future Windows versions. So there is no API to access it. This is an extremely hacky way to do it, might stop working at any time - for personal use only (tested on Windows 7):

import win32gui
import win32con
taskbar = win32gui.FindWindow("Shell_TrayWnd", None)
trayArea = win32gui.FindWindowEx(taskbar, None, "TrayNotifyWnd", None)
win32gui.SetForegroundWindow(taskbar)
win32gui.SendMessage(trayArea, win32con.WM_SETFOCUS, 0, 0)

Once again, do not use it in an application that other people will use. win32gui module is part of the Win32 Extensions.

For the hotkey you could use RegisterHotKey but it should be simpler to let Explorer handle that - add a link to your script to the Start menu and define a hotkey for it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜