Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: AutoHotKey - Editing a field box automatically and pasting the clipboard problem (Read 972 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

AutoHotKey - Editing a field box automatically and pasting the clipboard problem

I'm having trouble getting an ahk script to work with AutoHotkey. This issue only comes up with foobar.

What I'm trying to do is once I'm over a certain control like the genre field control is to do:
1. Click then pause till it goes into edit mode
2. Select all text in the edit field
3. Paste
4. Enter

It appears ahk has trouble focusing foobar with this simple command, which could be the cause of my problem:
Code: [Select]
winactivate, ahk_exe foobar2000.exe

Here's my code which currently not is working but it's a glimpse at what I'm trying to achieve for those of you that know ahk more than I do and could help out:
Code: [Select]
If WinActive("ahk_Exe foobar2000.exe") {
  ; MsgBox foobar2000.exe is active.
  ControlGetFocus, ctrlWithFocus
  ; I'm using Columns UI, so these controls below may differ.
  If (ctrlWithFocus = "NGLV3") {
    MsgBox foobar2000.exe is active and over the NGLV3 control.
    Send {LButton}
    sleep 500
    Send {LButton}
    sleep 600
    ControlGetFocus, ctrlWithFocus
    If (ctrlWithFocus = "Edit4") {
      MsgBox foobar2000.exe is active and over the Edit4 control.
      Send ^a
      sleep 200
      Send ^v
      sleep 200
      Send {ENTER}
    }
  }
}

Re: AutoHotKey - Editing a field box automatically and pasting the clipboard problem

Reply #1
Got it working. Had to hack my way through it.

Code: [Select]
; Help found on my thread here:
; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=76422&start=20

; AutoHotKey to quickly paste stuff into URL address bars and other such paraphernalia.

; What this does in detail:
; 1. Clicks where the mouse position is.
; 2. Selects all.
; 3. Pastes.
; 4. Enter key to enter the value.

; What it does in foobar2000.
; 1. Slow clicks over a tag field which goes into edit mode.
; 2. Selects all text in the tag field.
; 3. Pastes.
; 4. Enters to enter the value.

If WinActive("ahk_Exe foobar2000.exe") {
  ; This seems to be the fix to use the middle mouse button to refocus foobar2000.
  ; Will try to find a better solution if this fails hard.
  Send {MButton}
  ControlGetFocus, ctrlWithFocus
  If (ctrlWithFocus = "NGLV3") {
    ; MsgBox foobar2000.exe is active and over NGLV3 control.
    Send {LButton}
    sleep 500
    Send {LButton}
    sleep 600
    ControlGetFocus, ctrlWithFocus
    If (ctrlWithFocus = "Edit4") {
      ; MsgBox foobar2000.exe is active and over the Edit4 control.
      Send ^a
      sleep 200
      Send ^v
      sleep 200
      Send {ENTER}
    }
  }
} else {
  Send {LButton}
  sleep 100
  Send ^a
  sleep 100
  Send ^v
  sleep 100
  Send {ENTER}
}