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
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

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

Post by mikeyww » 27 Jan 2023, 22:04

There is something called an auto-execute section. It belongs at the top of the script, not the bottom. See the documentation.

You wouldn't actually use this script with a MsgBox from the same script. First, a MsgBox pauses the script until resolved. Second, you don't need to wait for something that you know is going to appear because it is programmed into your script. You can thus handle that issue directly, instead of having code that waits for it. Before you execute the MsgBox command, you can copy its text to the clipboard, or adjust the text in any way you wish. You then have what you want.

Code: Select all

#Requires AutoHotkey v1.1.33

!k::msg("12+f= asdf`nwer wer")

msg(txt) {
 Clipboard := RegExReplace(txt, "(\s.*|\W)") 
 MsgBox % txt
}

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 » 28 Jan 2023, 01:51

mikeyww wrote:
27 Jan 2023, 22:04
There is something called an auto-execute section. It belongs at the top of the script, not the bottom. See the documentation.

You wouldn't actually use this script with a MsgBox from the same script. First, a MsgBox pauses the script until resolved. Second, you don't need to wait for something that you know is going to appear because it is programmed into your script. You can thus handle that issue directly, instead of having code that waits for it. Before you execute the MsgBox command, you can copy its text to the clipboard, or adjust the text in any way you wish. You then have what you want.

Code: Select all

#Requires AutoHotkey v1.1.33

!k::msg("12+f= asdf`nwer wer")

msg(txt) {
 Clipboard := RegExReplace(txt, "(\s.*|\W)") 
 MsgBox % txt
}
THANK YOU SO MUCH!! That worked!!
You are super helpful here and I am grateful for your putting in time to help all of us (clueless) noobies. It's truly awesome how some of some of you experts are so willing to help others out here.
AHK is awesome and you've made it even better. I wish there was a way to give a bigger thanks. You deserve all of credit!

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

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

Post by andymbody » 28 Jan 2023, 19:19

samt wrote:
27 Jan 2023, 21:44
Even if I copy and paste your code below, the script doesn't seem to copy the content in the msgbox that pops up.
Hope this helps in your understanding...

As @mikeyww pointed out... the reason this did not work is because the msgbox popped up, paused the script (waiting to be closed), then once you closed the msgbox, the loop started watching for the msgbox that had already been closed by you.

This is the reason for the timers in the other SAMPLE scripts... so the script can watch for the msgbox and catch the text before the msgbox is closed. The timer simulates synchronous coding - simulating doing 2 things at once... also known as multi-threading. (My understanding is that AHK v1 does not actually support multi-threading, but it can appear so using timers)

The timers are only required in the sample scripts, to allow you to run the script as is, see that it works, then for you to extract just the parts of the script that are required to get your script to work. I would have provided more instruction had I known your current coding knowledge level.

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 » 29 Jan 2023, 02:09

andymbody wrote:
28 Jan 2023, 19:19
samt wrote:
27 Jan 2023, 21:44
Even if I copy and paste your code below, the script doesn't seem to copy the content in the msgbox that pops up.
Hope this helps in your understanding...

As @mikeyww pointed out... the reason this did not work is because the msgbox popped up, paused the script (waiting to be closed), then once you closed the msgbox, the loop started watching for the msgbox that had already been closed by you.

This is the reason for the timers in the other SAMPLE scripts... so the script can watch for the msgbox and catch the text before the msgbox is closed. The timer simulates synchronous coding - simulating doing 2 things at once... also known as multi-threading. (My understanding is that AHK v1 does not actually support multi-threading, but it can appear so using timers)

The timers are only required in the sample scripts, to allow you to run the script as is, see that it works, then for you to extract just the parts of the script that are required to get your script to work. I would have provided more instruction had I known your current coding knowledge level.
Yes, this is all great info. And thanks for your tips. Don't worry about!
There is much to learn on my part!

Post Reply

Return to “Ask for Help (v1)”