Program flash

If you have a question or need help, this is the place to be.
Post Reply
z3us
Posts: 42
Joined: Fri Jul 29, 2011 2:35 am

Program flash

Post by z3us » Mon Sep 16, 2019 2:51 am

Hi. Is it possible for EG to detect when a program icon flashes on the taskbar and create an event?
Thx

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Program flash

Post by kgschlosser » Mon Sep 16, 2019 1:45 pm

That is a good question..

and it is something that can be done. It is going to require some pretty in depth python coding using ctypes and tapping into the windows api to do a shell hook. and having the messages sent to the main message receiver in eg.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Program flash

Post by kgschlosser » Mon Sep 16, 2019 2:08 pm

I have not tested this code at all. it may work.. LOL

place this code into a python script action and place the action in your Autostart group

Code: Select all

import ctypes
from ctypes.wintypes import BOOL, INT
from eg.WinApi.Utils import GetWindowProcessName

user32 = ctypes.windll.User32
# int GetWindowTextLengthW(
#   HWND hWnd
# );
GetWindowTextLengthW = user32.GetWindowTextLengthW
GetWindowTextLengthW.restype = INT

# int GetWindowTextW(
#   HWND   hWnd,
#   LPWSTR lpString,
#   int    nMaxCount
# );

GetWindowTextW = user32.GetWindowTextW
GetWindowTextW.restype = INT

# BOOL RegisterShellHookWindow(
#   HWND hwnd
# );
RegisterShellHookWindow = user32.RegisterShellHookWindow
RegisterShellHookWindow.restype = BOOL

HSHELL_REDRAW = 6
HSHELL_HIGHBIT = 0x8000
HSHELL_FLASH = HSHELL_REDRAW | HSHELL_HIGHBIT


def callback(hwnd, *_):
    nMaxCount = GetWindowTextLengthW(hwnd)
    lpString = ctypes.create_unicode_buffer(nMaxCount)
    GetWindowTextW(hwnd, lpString, nMaxCount)

    process_name = GetWindowProcessName(hwnd)

    eg.TriggerEvent(
        prefix='Application',
        suffix='Attention.Request.' + lpString.value,
        payload=dict(handle=hwnd, procss_name=process_name)
    )

eg.messageReceiver.AddHandler(HSHELL_FLASH, callback)
RegisterShellHookWindow(eg.messageReceiver.hwnd)
this only needs to run a single time in order to work. that is why it has to be placed in the autostart. so it will run when EG starts up.
If you like the work I have been doing then feel free to Image

Post Reply