Can AHK detect when Action Center notifications occur?
Re: Can AHK detect when Action Center notifications occur?
I question I have is whether AutoHotKey can detect when my computer loses Internet. That would be nice since the TextNow app I use has a "Quit" option when you right-click on its icon in the Action Center. Is there a way to make "Quit" occur whenever my computer loses Internet?
- Gurkentoepfer
- Posts: 49
- Joined: 24 Feb 2014, 14:52
Re: Can AHK detect when Action Center notifications occur?
Thank you, @Gurkentoepfer! This should allow me to detect when there's an Internet connection. As for the command, how can I make AutoHotKey fully close my TextNow app whenever no Internet connection is available? For reference, the app's name is "TextNow - Unlimited Text + Calls".Gurkentoepfer wrote: ↑25 Oct 2022, 08:44https://www.autohotkey.com/board/topic/111086-solved-check-if-connected-to-the-internet/
Re: Can AHK detect when Action Center notifications occur?
can someone please help?
I don't get any meningful output with this script, I generated a new message and then tried to read it with ahk, using code that malcev suggested. But every time my msgbox message was "no info"
I tried to run script that should detect AppName from notifications in action center. But result was the same - no info.
then I changed the following condition
to
and I got the app name and notification message, but there was a memory error at the end and I removed this piece of code:
here's a screenshot of the error message: https://prnt.sc/iekaOSFWH6Ac
everything seems to be working fine, but it feels like I'll run into issues later using the code as it is now
here's what my code looks like now:
I don't get any meningful output with this script, I generated a new message and then tried to read it with ahk, using code that malcev suggested. But every time my msgbox message was "no info"
I tried to run script that should detect AppName from notifications in action center. But result was the same - no info.
then I changed the following condition
Code: Select all
if !DllCall(NumGet(NumGet(UserNotification+0)+7*A_PtrSize), "ptr", UserNotification, "ptr*", AppInfo) ; get_AppInfo
Code: Select all
if true
Code: Select all
text := StrGet(buffer, "UTF-16")
everything seems to be working fine, but it feels like I'll run into issues later using the code as it is now
here's what my code looks like now:
Code: Select all
setbatchlines -1
CreateClass("Windows.UI.Notifications.Management.UserNotificationListener", IUserNotificationListenerStatics := "{FF6123CF-4386-4AA3-B73D-B804E5B63B23}", UserNotificationListenerStatics)
DllCall(NumGet(NumGet(UserNotificationListenerStatics+0)+6*A_PtrSize), "ptr", UserNotificationListenerStatics, "ptr*", listener) ; get_Current
DllCall(NumGet(NumGet(listener+0)+6*A_PtrSize), "ptr", listener, "int*", accessStatus) ; RequestAccessAsync
WaitForAsync(accessStatus)
if (accessStatus != 1)
{
msgbox AccessStatus Denied
exitapp
}
loop
{
DllCall(NumGet(NumGet(listener+0)+10*A_PtrSize), "ptr", listener, "int", 1, "ptr*", UserNotificationReadOnlyList) ; GetNotificationsAsync
WaitForAsync(UserNotificationReadOnlyList)
DllCall(NumGet(NumGet(UserNotificationReadOnlyList+0)+7*A_PtrSize), "ptr", UserNotificationReadOnlyList, "int*", count) ; count
loop % count
{
DllCall(NumGet(NumGet(UserNotificationReadOnlyList+0)+6*A_PtrSize), "ptr", UserNotificationReadOnlyList, "int", A_Index-1, "ptr*", UserNotification) ; get_Item
DllCall(NumGet(NumGet(UserNotification+0)+8*A_PtrSize), "ptr", UserNotification, "uint*", id) ; get_Id
if InStr(idList, "|" id "|")
{
ObjRelease(UserNotification)
Continue
}
idList .= "|" id "|"
; this used to be if !DllCall(NumGet(NumGet(UserNotification+0)+7*A_PtrSize), "ptr", UserNotification, "ptr*", AppInfo) ; get_AppInfo[/code]
if true
{
DllCall(NumGet(NumGet(AppInfo+0)+8*A_PtrSize), "ptr", AppInfo, "ptr*", AppDisplayInfo) ; get_DisplayInfo
DllCall(NumGet(NumGet(AppDisplayInfo+0)+6*A_PtrSize), "ptr", AppDisplayInfo, "ptr*", hText) ; get_DisplayName
buffer := DllCall("Combase.dll\WindowsGetStringRawBuffer", "ptr", hText, "uint*", length, "ptr")
; had to comment out, otherwise causes memory error
;text := StrGet(buffer, "UTF-16")
DeleteHString(hText)
ObjRelease(AppDisplayInfo)
ObjRelease(AppInfo)
}
else
{
ObjRelease(UserNotification)
Continue
}
DllCall(NumGet(NumGet(UserNotification+0)+6*A_PtrSize), "ptr", UserNotification, "ptr*", Notification) ; get_Notification
DllCall(NumGet(NumGet(Notification+0)+8*A_PtrSize), "ptr", Notification, "ptr*", NotificationVisual) ; get_Visual
DllCall(NumGet(NumGet(NotificationVisual+0)+8*A_PtrSize), "ptr", NotificationVisual, "ptr*", NotificationBindingList) ; get_Bindings
DllCall(NumGet(NumGet(NotificationBindingList+0)+7*A_PtrSize), "ptr", NotificationBindingList, "int*", count) ; count
loop % count
{
DllCall(NumGet(NumGet(NotificationBindingList+0)+6*A_PtrSize), "ptr", NotificationBindingList, "int", A_Index-1, "ptr*", NotificationBinding) ; get_Item
DllCall(NumGet(NumGet(NotificationBinding+0)+11*A_PtrSize), "ptr", NotificationBinding, "ptr*", AdaptiveNotificationTextReadOnlyList) ; GetTextElements
DllCall(NumGet(NumGet(AdaptiveNotificationTextReadOnlyList+0)+7*A_PtrSize), "ptr", AdaptiveNotificationTextReadOnlyList, "int*", count) ; count
loop % count
{
DllCall(NumGet(NumGet(AdaptiveNotificationTextReadOnlyList+0)+6*A_PtrSize), "ptr", AdaptiveNotificationTextReadOnlyList, "int", A_Index-1, "ptr*", AdaptiveNotificationText) ; get_Item
DllCall(NumGet(NumGet(AdaptiveNotificationText+0)+6*A_PtrSize), "ptr", AdaptiveNotificationText, "ptr*", hText) ; get_Text
buffer := DllCall("Combase.dll\WindowsGetStringRawBuffer", "ptr", hText, "uint*", length, "ptr")
if (A_Index = 1)
text := StrGet(buffer, "UTF-16")
else
text .= "`n" StrGet(buffer, "UTF-16")
DeleteHString(hText)
ObjRelease(AdaptiveNotificationText)
}
ObjRelease(AdaptiveNotificationTextReadOnlyList)
ObjRelease(NotificationBinding)
msgbox % text
}
ObjRelease(NotificationBindingList)
ObjRelease(NotificationVisual)
ObjRelease(Notification)
ObjRelease(UserNotification)
}
ObjRelease(UserNotificationReadOnlyList)
DllCall("psapi.dll\EmptyWorkingSet", "ptr", -1)
sleep 50
}
CreateClass(string, interface, ByRef Class)
{
CreateHString(string, hString)
VarSetCapacity(GUID, 16)
DllCall("ole32\CLSIDFromString", "wstr", interface, "ptr", &GUID)
result := DllCall("Combase.dll\RoGetActivationFactory", "ptr", hString, "ptr", &GUID, "ptr*", Class, "uint")
if (result != 0)
{
if (result = 0x80004002)
msgbox No such interface supported
else if (result = 0x80040154)
msgbox Class not registered
else
msgbox error: %result%
ExitApp
}
DeleteHString(hString)
}
CreateHString(string, ByRef hString)
{
DllCall("Combase.dll\WindowsCreateString", "wstr", string, "uint", StrLen(string), "ptr*", hString)
}
DeleteHString(hString)
{
DllCall("Combase.dll\WindowsDeleteString", "ptr", hString)
}
WaitForAsync(ByRef Object)
{
AsyncInfo := ComObjQuery(Object, IAsyncInfo := "{00000036-0000-0000-C000-000000000046}")
loop
{
DllCall(NumGet(NumGet(AsyncInfo+0)+7*A_PtrSize), "ptr", AsyncInfo, "uint*", status) ; IAsyncInfo.Status
if (status != 0)
{
if (status != 1)
{
DllCall(NumGet(NumGet(AsyncInfo+0)+8*A_PtrSize), "ptr", AsyncInfo, "uint*", ErrorCode) ; IAsyncInfo.ErrorCode
msgbox AsyncInfo status error: %ErrorCode%
ExitApp
}
ObjRelease(AsyncInfo)
break
}
sleep 10
}
DllCall(NumGet(NumGet(Object+0)+8*A_PtrSize), "ptr", Object, "ptr*", ObjectResult) ; GetResults
ObjRelease(Object)
Object := ObjectResult
}
Re: Can AHK detect when Action Center notifications occur?
I've just realized I'm still running version 1 of ahk, I'm switching to v 2, will post an update in a few days.