okay, I've used both codes in their own scripts with nothing else but their own msgbox so I can test things out. For some reason I can't get them to copy only the first word from the msg box, or automatically. (I have the below code running in a different script to format out all of the "---" and stuff) I tried your most recent script you posted as well but I still cant get it to only copy the first word from the msg box. I've tested the 2nd code below with and without running the code directly below, and only when I have the code running below does it clean up my msgboxes.
The code below is from malcev. Its what I need to run all of this code on that will pop up a msgbox. With that script, when I receive a desktop/action center notification from Brave Browser, it will pop up a msgbox with the notification content, and open a certain program depending on if the 'if' condition is met or not. What I need help with is to make the script automatically copy just the first word from the msgbox that pops up (examples in my first post, like I only need "IDJ" from "IDJ, this document goes..." in the msgbox, so without any non-letters, commas, etc (Haven't been able to do this anywhere yet). I also don't really know where I'd put the scripts that you guys have posted here into the script below and I've tried different places and made make sure I have the right variable. The code between lines of " ; ********** " are the only parts I made changes to the script
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance
; ***************************
AppName := "Brave" ; Script activates when I receive a notification from Brave (Brave Browser)
Forma := "Document7" ; look for this word in the brave browser notification content
; ***************************
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 "|"
if !DllCall(NumGet(NumGet(UserNotification+0)+7*A_PtrSize), "ptr", UserNotification, "ptr*", AppInfo) ; get_AppInfo
{
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")
text := StrGet(buffer, "UTF-16")
DeleteHString(hText)
ObjRelease(AppDisplayInfo)
ObjRelease(AppInfo)
if (text != AppName)
{
ObjRelease(UserNotification)
Continue
}
}
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)
; **************************************************
; variable 'text' contains the content of the notification, and displays it in a msgbox
; tried all sorts of code here you guys posted on this thread but it seems no luck
if text contains %Forma% ; executes if statement if Document7 is in notification content
{
msgbox % text
; WinWaitActive ahk_class #32770
; ControlGetText text, Static1 ; cant get these to auto copy only the first word in the msgbox. Tried other codes you guys posted as well
; Clipboard := RegExReplace(StrSplit(SubStr(txt, InStr(txt, "`n") + 1), " ").1, "\W")
}
else {
msgbox % text
; WinWaitActive ahk_class #32770
; ControlGetText text, Static1 ; also doesnt work
; Clipboard := RegExReplace(StrSplit(SubStr(txt, InStr(txt, "`n") + 1), " ").1, "\W")
}
; *************************************************
ObjRelease(NotificationBindingList)
ObjRelease(NotificationVisual)
ObjRelease(Notification)
ObjRelease(UserNotification)
}
ObjRelease(UserNotificationReadOnlyList)
DllCall("psapi.dll\EmptyWorkingSet", "ptr", -1)
sleep 300
}
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
}
; ********************** Tried this and other similar codes here but doesnt seem to work
/*
#Requires AutoHotkey v1.1.33
winTitle := "ahk_class #32770"
Loop {
WinWaitActive % winTitle
ControlGetText text, Static1
Clipboard := RegExReplace(text, "(\s.*|\W)") ; 12+f= asdf`nwer wer => 12f
SoundBeep 1500 ; the soundbeep has never worked
WinWaitNotActive
*/
; *************************
}