copy msg box, save only the first word into clipboard and exclude non-letters Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
samt
Posts: 62
Joined: 09 Sep 2022, 13:29

copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 26 Jan 2023, 02:36

I'm trying to make a script so that when a msgbox pops up, it's text will be automatically copied, and then the script will only save the first word of the content copied, and I want it to exclude non-letters like , and : when saving to clipboard.
So, if a msg box pops up and shows "IDA, This continued yesterday...", the text will be automatically copied, and the script will only save the first word into the clipboard without the : or anything else like , or + . So I only want to extract "IDA" so that when I paste into another program, IDA will be pasted. Or another example, if msgbox shows "IDKU+ and up will not..." I only want to extract and paste "IDKU" into a different program. Right now I'm manually copying and pasting, so the script runs when I manually copy from a msgbox and the script edits the content into the first word only with no non-letters. Dont know why but sometimes it works, sometimes it doesnt, and it even runs the script sometimes if I copy from another program like a browser, when it should only run when I copy from a msgbox, thought I actually need it to auto copy a msgbox when it pops up.

Code: Select all

#Persistent
OnClipboardChange("CleanMsgBox")
return

CleanMsgBox() {
	#IfWinActive ahk_class #32770
		Clipboard := RegExReplace(Clipboard, "s)\v*---------------.*?---------------------\v*") ; I included this cus sometimes a msgbox will have a bunch of "----------" in it. This works sometimes, and sometimes doesnt
}


#IfWinActive ahk_class #32770  ; to ensure msgbox is active window to execute script 
send, ^c
onClipboardChange:
clipsaved:= ClipboardAll 
clip := substr(clipboard, 1, 4) ; the first 5 letters from the text on the clipboard
ClipWait, 1
clipboard := clip ; store the copied text in clip variable from msgbox into clipboard
Tooltip % clip ; just to quickly showed what's been copied
Sleep 1500
Tooltip
Clipboard := ClipSaved
return

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by mikeyww » 26 Jan 2023, 08:20

This works for a MsgBox with one button. It would need adjustment for a MsgBox with more than one button, because the leading window text contains the button text.

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance Force
winTitle := "ahk_class #32770"
Loop {
 WinWaitActive % winTitle
 SoundBeep 1500
 WinGetText txt
 Clipboard := RegExReplace(StrSplit(SubStr(txt, InStr(txt, "`n") + 1), " ").1, "\W")
 WinWaitNotActive
}

Code: Select all

#Requires AutoHotkey v2.0
winTitle := "ahk_class #32770"
Loop {
 WinWaitActive winTitle
 SoundBeep 1500
 txt := WinGetText()
 A_Clipboard := RegExReplace(StrSplit(SubStr(txt, InStr(txt, "`n") + 1), " ")[1], "\W")
 WinWaitNotActive
}

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 26 Jan 2023, 15:24

mikeyww wrote:
26 Jan 2023, 08:20

Code: Select all

winTitle := "ahk_class #32770"
Loop {
 WinWaitActive winTitle
 SoundBeep 1500
 txt := WinGetText()
  A_Clipboard := txt  ; also tried it without this line 
 A_Clipboard := RegExReplace(StrSplit(SubStr(txt, InStr(txt, "`n") + 1), " ")[1], "\W")
 WinWaitNotActive
}
I used the your above code since I use V2, and also tried it by adding my line which you see at line 6. My msgbox has 1 button. Not sure why but the code doesn't work, it still copies everything in the msg box. I had to get rid of the "()" after WinGetText otherwise I'd get an error when trying to run the script. I tried modifying it more as below but that still doesn't work. Also, I think WinWaitActive is for AHK v1? As a newby I'm not sure if that means if that line is still usable in V2 or not --> https://www.autohotkey.com/docs/v1/lib/WinWaitActive.htm

Code: Select all

Loop {
 #IfWinActive ahk_class Notepad  ; using notepad for testing purposes
 SoundBeep 1500
 txt := WinGetText
 A_Clipboard := txt  ; also tried it without this line 
 A_Clipboard := RegExReplace(StrSplit(SubStr(txt, InStr(txt, "`n") + 1), " ")[1], "\W")
}
[Mod edit: Changed code box from .txt type to default .ahk type.]

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by boiler » 26 Jan 2023, 16:48

samt wrote: I used the your above code since I use V2
You might think you do, but your code is v1 code and the things you had to change to avoid errors were due to you not using v2 to run the code.

All of your posts in your past threads are v1 as well.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by mikeyww » 26 Jan 2023, 17:11

If you have a script that displays the MsgBox, you can also post that script.

The AutoHotkey Web site includes documentation for both v1 and v2. Thus, there is no need to be uncertain about the commands, functions, & syntax for each!

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 26 Jan 2023, 17:27

boiler wrote:
26 Jan 2023, 16:48
samt wrote: I used the your above code since I use V2
You might think you do, but your code is v1 code and the things you had to change to avoid errors were due to you not using v2 to run the code.

All of your posts in your past threads are v1 as well.
Oh I see...I just software updated my autohotkey program just yesterday for the first time into V2 (2.02 exactly). So before yesterday, it was V1. After I updated it, I closed all my scripts and re-opened them. What else do I need to do to ensure I'm actually using the latest version after installing it? I thought it would automatically replace V1. I opened autohotkey after updating it and the thing that pops up is a small window, and then I closed it cus I dont think I need it.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by mikeyww » 26 Jan 2023, 17:54

Installing v2 does not actually remove v1, and the two versions can coexist and run scripts in their own version. This is actually explained on the Web site as well.

https://www.autohotkey.com/docs/v2/howto/Install.htm

https://www.autohotkey.com/docs/v2/Program.htm#launcher

The syntax differs, so a v1 script will usually not run under v2, but there is no need to convert anything since you would have both versions. I would read the two pages mentioned here.

My earlier post shows examples of how to use #Requires.

User avatar
andymbody
Posts: 867
Joined: 02 Jul 2017, 23:47

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by andymbody » 26 Jan 2023, 20:07

samt wrote:
26 Jan 2023, 02:36
I'm trying to make a script so that when a msgbox pops up, it's text will be automatically copied
I believe the code below is incorrect?

Code: Select all

CleanMsgBox() {
	#IfWinActive ahk_class #32770
		Clipboard := RegExReplace(Clipboard, "s)\v*---------------.*?---------------------\v*")
}
Should it be this code by @Boiler?
viewtopic.php?f=76&t=74302

Code: Select all

CleanMsgBox() {
	if WinActive("ahk_class #32770")
		Clipboard := RegExReplace(Clipboard, "s)\v*---------------------------.*?---------------------------\v*")
}


Also Send, ^c does not seem to copy msgbox contents, when doing so via code



Here is an example of how to extract the text you are interested in. Using the ControlGetText seems to be effective

Code: Select all


#SingleInstance, force
#Persistent

SetTimer, watchMB, 100
Sleep, 2000

MsgBox,0, Test, IDKU+ and up will not...
return

esc::ExitApp

watchMB:
	mbText := ""
	IfWinActive, ahk_class #32770
	{
		ControlGetText, mbText, Static1, ahk_class #32770
		RegExMatch(mbText, "^\w+", mbText)
	}
	ToolTip % "mbText := [" . mbText . "]"
	return
	
Last edited by andymbody on 26 Jan 2023, 20:27, edited 1 time in total.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by mikeyww » 26 Jan 2023, 20:15

Perhaps also:

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance Force
winTitle := "ahk_class #32770"
Loop {
 WinWaitActive % winTitle
 ControlGetText txt, Static1
 Clipboard := RegExReplace(txt, "(\s.*|\W)") ; 12+f= asdf`nwer wer => 12f
 SoundBeep 1500
 WinWaitNotActive
}

User avatar
andymbody
Posts: 867
Joined: 02 Jul 2017, 23:47

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by andymbody » 26 Jan 2023, 20:48

mikeyww wrote:
26 Jan 2023, 20:15
RegExReplace(txt, "(\s.*|\W)")
Interesting... thanks for the tip

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 27 Jan 2023, 13:38

mikeyww wrote:
26 Jan 2023, 08:20
This works for a MsgBox with one button. It would need adjustment for a MsgBox with more than one button, because the leading window text contains the button text.
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.

(code 1)

Code: Select all

OnClipboardChange("CleanMsgBox") ; have this code running in a diff script
return

CleanMsgBox() {
	if WinActive("ahk_class #32770")
		Clipboard := RegExReplace(Clipboard, "s)\v*---------------------------.*?---------------------------\v*")
}
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

(code2)

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
*/
; *************************

}

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 27 Jan 2023, 14:20

mikeyww wrote:
26 Jan 2023, 17:54
Installing v2 does not actually remove v1, and the two versions can coexist and run scripts in their own version. This is actually explained on the Web site as well.

https://www.autohotkey.com/docs/v2/howto/Install.htm

https://www.autohotkey.com/docs/v2/Program.htm#launcher

The syntax differs, so a v1 script will usually not run under v2, but there is no need to convert anything since you would have both versions. I would read the two pages mentioned here.

My earlier post shows examples of how to use #Requires.
This is good to know, thanks. I'm glad I dont need to convert my current scripts. Do you think we will ever need to convert V1 scripts to V2 eventually? Like mandatory? I know that there's that autohotkey converter on github. I've tried it, seems good, though it misses a few lines.

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by boiler » 27 Jan 2023, 15:43

samt wrote: Do you think we will ever need to convert V1 scripts to V2 eventually? Like mandatory?
Converting scripts to a new version will never be mandatory. How could that be enforced even if someone wanted to do that? There's no registration that could be revoked or anything like that. As long as you have it installed, you can keep using it as long as you want. And you can always download past versions from this website. There are people who still use AHK "Basic" (v1.0....) because they have scripts that were written in it and there is no reason to convert them.

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 27 Jan 2023, 15:53

boiler wrote:
27 Jan 2023, 15:43
samt wrote: Do you think we will ever need to convert V1 scripts to V2 eventually? Like mandatory?
Converting scripts to a new version will never be mandatory. How could that be enforced even if someone wanted to do that? There's no registration that could be revoked or anything like that. As long as you have it installed, you can keep using it as long as you want. And you can always download past versions from this website. There are people who still use AHK "Basic" (v1.0....) because they have scripts that were written in it and there is no reason to convert them.
Good. I can see how you're right.

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 27 Jan 2023, 16:10

boiler wrote:
27 Jan 2023, 15:43
samt wrote: Do you think we will ever need to convert V1 scripts to V2 eventually? Like mandatory?
Converting scripts to a new version will never be mandatory. How could that be enforced even if someone wanted to do that? There's no registration that could be revoked or anything like that. As long as you have it installed, you can keep using it as long as you want. And you can always download past versions from this website. There are people who still use AHK "Basic" (v1.0....) because they have scripts that were written in it and there is no reason to convert them.
I forgot to ask.. do newer version of AHK, like V2, run more efficiently/use less resources/computing power than V1? I was curious about that.

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by boiler » 27 Jan 2023, 19:44

samt wrote: do newer version of AHK, like V2, run more efficiently/use less resources/computing power than V1?
I'm thinking that it's possible that it's marginally more efficient just because lexikos may have written code that is more efficient than the original AHK code, but I haven't heard of this mentioned as an advantage of v2 over v1, and if it is true, it is likely that it wouldn't even be noticeable.

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by mikeyww » 27 Jan 2023, 20:07

I was thinking the same thing, and also that you can answer your question by running two scripts and then examining the Windows Task Manager.

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 27 Jan 2023, 20:59

andymbody wrote:
26 Jan 2023, 20:07

Here is an example of how to extract the text you are interested in. Using the ControlGetText seems to be effective

Code: Select all


#SingleInstance, force
#Persistent

SetTimer, watchMB, 100
Sleep, 2000

MsgBox,0, Test, IDKU+ and up will not...
return

esc::ExitApp

watchMB:
	mbText := ""
	IfWinActive, ahk_class #32770
	{
		ControlGetText, mbText, Static1, ahk_class #32770
		RegExMatch(mbText, "^\w+", mbText)
	}
	ToolTip % "mbText := [" . mbText . "]"
	return
	
ControlGetText says it retrieves text from a "control", what exactly does that mean, "Control"? I'm not quite sure how to use that

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by mikeyww » 27 Jan 2023, 21:07

Although writing a script requires knowing how to code it, I have also found that running a script can be educational in itself. When you see what a script does and then examine its code, many inferences can be drawn, and understanding can often be gained. You might want to give it a go. Running Window Spy will also show you control names.

To answer your question, "What is a control?" see https://learn.microsoft.com/en-us/windows/win32/controls/window-controls.

samt
Posts: 62
Joined: 09 Sep 2022, 13:29

Re: copy msg box, save only the first word into clipboard and exclude non-letters

Post by samt » 27 Jan 2023, 21:44

mikeyww wrote:
27 Jan 2023, 21:07
Although writing a script requires knowing how to code it, I have also found that running a script can be educational in itself. When you see what a script does and then examine its code, many inferences can be drawn, and understanding can often be gained. You might want to give it a go. Running Window Spy will also show you control names.

To answer your question, "What is a control?" see https://learn.microsoft.com/en-us/windows/win32/controls/window-controls.
So far I've only been able to get one of these codes from this thread working, I don't know why, and I try them with a clean slate.
Even if I copy and paste your code below, the script doesn't seem to copy the content in the msgbox that pops up. I dont know what I'm doing wrong. I have yet to be able to get any of these scripts in this thread to auto-copy whatever appears in a msgbox that pops up from that same script, for the scripts that are supposed to do that.

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance Force

!k::
MsgBox, testing

; your code below I copied
winTitle := "ahk_class #32770"
Loop {
 WinWaitActive % winTitle
 SoundBeep 1500
 WinGetText txt
 Clipboard := RegExReplace(StrSplit(SubStr(txt, InStr(txt, "`n") + 1), " ").1, "\W")
 WinWaitNotActive
}

Post Reply

Return to “Ask for Help (v1)”