Getting text from textBox Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Holarctic
Posts: 2
Joined: 18 Apr 2024, 07:21

Getting text from textBox

18 Apr 2024, 07:35

Hello,
Im trying to create a script that will take some text in textbox in browser and run regexReplace on it and then replace the original text with updated text.
Currently my issue is getting the text from the window into the variable inside the script. I tried using Clipboard, but it ever only used the first thing I got in it, it worked only the first time I run the script, eg. I run the script to copy "first" and put it into MsgBox it works, but when I have it copy "second" it shows "first".
I'm asking for help how to get text from textbox in browser so I can edit it.
Here is the code I used to get text into the script:

Code: Select all

    clipSaved := ClipboardAll
    Clipboard := ""
    ClipWait(2, 1) 
    Send "^a"
    Send "^c"
    ClipWait(2, 1) 
    test := A_Clipboard
    MsgBox test

    Clipboard := ""
    Clipboard := clipSaved
    ClipWait(2, 1)

Goal is to have a script that removes all text between parenthesis () in a textbox
"This is (an) example" -> "This is example"
im on windows 11 and have clipboard enabled (win+v) and Im using ahk v2
Holarctic
Posts: 2
Joined: 18 Apr 2024, 07:21

Re: Getting text from textBox

18 Apr 2024, 07:54

Additional info: textbox will be focused when running the script, but I dont have info on the name of the window just that its one of the browsers. Im running the script with win+j key combo
User avatar
mikeyww
Posts: 27205
Joined: 09 Sep 2014, 18:38

Re: Getting text from textBox  Topic is solved

18 Apr 2024, 07:55

Welcome to this AutoHotkey forum!

I would refer to the :arrow: Example, and note the use of A_Clipboard throughout the script.
Renamed:

Clipboard → A_Clipboard

Source: Changes from v1.1 to v2.0 | AutoHotkey v2

Code: Select all

#Requires AutoHotkey v2.0

#j Up:: {
 Static regex := '\(.*?\)\h*'
 KeyWait 'LWin'
 A_Clipboard := ''
 Send '^a^c'
 If ClipWait(1)
  SendText RegExReplace(A_Clipboard, regex)
 Else MsgBox 'An error occurred while waiting for the clipboard.', 'Error', 'Icon!'
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: niCode, Rohwedder, trpldss and 21 guests