Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Trouble with ControlClick!


  • Please log in to reply
9 replies to this topic
Jim Yuill
  • Members
  • 6 posts
  • Last active: Sep 21 2008 02:38 AM
  • Joined: 15 Sep 2008
.
.
I can't figure out how to get this ControlClick command to work. Can anyone help?!

I need my hot-key to click on the line "Unformatted Text" in the window shown below. The Window Spy output is also shown, for when I manually click on "Unformatted Text".

I can open that window via AHK. But my attempts at ControlClick do NOT work, such as:

    SetTitleMatchMode,Slow
    SetControlDelay -1
    ControlClick,REListBox20W1,ahk_class #32770,Unformatted Text

Any help is much appreciated!


Posted Image

Posted Image[/code]

Me!
  • Members
  • 46 posts
  • Last active: Aug 26 2011 07:56 AM
  • Joined: 20 Sep 2007
Try ControlSend u

SetTitleMatchMode,Slow
    SetControlDelay -1
    ControlSend, REListBox20W1,u,ahk_class #32770,Unformatted Text

if that doesnt work
ControlFocus on that control

if that doesn't work try clicking by X,Y coordinates
ControlClick,X283 Y149,ahk_class #32770


n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Or try Control, ChooseString, String.
Or if that doesn't work, do a ControlFocus and an amount of {Down} keys (or a single key, like "u", if that makes the listview jump to the wanted selection).

HTH
________________________________________________________
New here? Please, before you post...
1. Read the tutorial and try the examples. -> 2. Take a look at the command list to get an idea of what you could do. -> 3. Create your script. Consult the documentation and the FAQ if you get stuck. -> 4. Search the forum if you need help or examples, method 1 (forum), method 2 (site), method 3 (Google). -> 5. Post your code on the forum in the "Ask for Help" section if you still run into problems (but read this first). -> 6. There is more AHK on autohotkey.net and the Wiki and there is an AHK IRC chat.


Jim Yuill
  • Members
  • 6 posts
  • Last active: Sep 21 2008 02:38 AM
  • Joined: 15 Sep 2008
.
I'm replying to "me!" here...

THANKS for the help.

I tried all three of your suggestions, but unfortunately, they don't work quite right here. FYI, the GUI I'm working with is from PowerPoint.

ControlSend is not accurate in its selection here. In the screen shot I posted, the list has two items that start with "P". The ControlSend will just select the first one, even when the text of the second is specified, e.g.,

ControlSend, REListBox20W1,p,ahk_class #32770, Picture (Enhanced Metafile)


ControlFocus didn't work in selecting the "Unformatted Text" list item:

mystring = Unformatted Text
ControlFocus, REListBox20W1, ahk_class #32770, %mystring%


Clicking by x,y coordinates won't work consistently as the list items will change, depending on what is being pasted.

I'm wondering if I'm writing these commands incorrectly? Or, is PowerPoint doing something weird, internally?

Again, any advice is much appreciated,

Jim

Jim Yuill
  • Members
  • 6 posts
  • Last active: Sep 21 2008 02:38 AM
  • Joined: 15 Sep 2008
.
I'm replying to "n-l-i-d" here. THANKS much for the help.

I tried your suggestions, but unfortunately, they don't work quite right here. (FYI, the GUI I'm working with is from PowerPoint.)

The Control, ChooseString, String didn't work:

mystring = Unformatted Text
Control, ChooseString, %mystring%, REListBox20W1

Sending "down keys" or "u" won't work consistently, as the list items are not always the same.

Any other ideas? Any help is really appreciated

Jim


BTW: I've tried many different AHK functions, but none have worked so far:

ControlClick,Unformatted Text
ControlClick,,,Unformatted
ControlClick,REListBox20W1,,Unformatted
ControlClick,Unformatted Text,A
ControlClick,Unformatted Text, ahk_class #32770
ControlClick,REListBox20W1,ahk_class #32770,Unformatted
ControlClick,REListBox20W1,ahk_class #32770,Unformatted Text

WinMenuSelectItem,ahk_class PP10FrameClass,, Edit, Paste Special

Control, ChooseString, Unformatted Text, REListBox20W1

mystring = Unformatted Text
Control, ChooseString, %mystring%, REListBox20W1

mystring = Unformatted Text
ControlFocus, REListBox20W1, ahk_class #32770, %mystring%


n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Does this give you a number (or "FAIL")?

SendMessage, (EM_GETLINECOUNT := 0xBA), 0, 0, REListBox20W1, ahk_class #32770
nrOfLinesInList := ErrorLevel
MsgBox % nrOfLinesInList
________________________________________________________
New here? Please, before you post...
1. Read the tutorial and try the examples. -> 2. Take a look at the command list to get an idea of what you could do. -> 3. Create your script. Consult the documentation and the FAQ if you get stuck. -> 4. Search the forum if you need help or examples, method 1 (forum), method 2 (site), method 3 (Google). -> 5. Post your code on the forum in the "Ask for Help" section if you still run into problems (but read this first). -> 6. There is more AHK on autohotkey.net and the Wiki and there is an AHK IRC chat.


n-l-i-d
  • Guests
  • Last active:
  • Joined: --
Here is the complete script (not tested). Does this work?
wantedOption = Picture

; get number of lines in the "listbox"
SendMessage, (EM_GETLINECOUNT := 0xBA), 0, 0, REListBox20W1, ahk_class #32770
nrOfLinesInList := ErrorLevel 

Loop %nrOfLinesInList%
{
   ; get contents of this line
   VarSetCapacity(thisLine, 100)
   SendMessage, (EM_GETLINE := 0xC4), A_Index-1, &thisLine, REListBox20W1, ahk_class #32770

   ; if it is the wanted option...
   If (thisLine = %wantedOption%)
   {
      ; get starting position of line
      SendMessage, (EM_LINEINDEX := 0xBB), A_Index-1, 0, REListBox20W1, ahk_class #32770
      lineStart := ErrorLevel

      ; get length of line
      SendMessage, (EM_LINELENGTH := 0xC1), A_Index-1, 0, REListBox20W1, ahk_class #32770
      lineLen := ErrorLevel

      ; select the line
      SendMessage, (EM_SETSEL := 0xB1), lineStart, lineStart+lineLen, REListBox20W1, ahk_class #32770
   }
}

HTH
________________________________________________________
New here? Please, before you post...
1. Read the tutorial and try the examples. -> 2. Take a look at the command list to get an idea of what you could do. -> 3. Create your script. Consult the documentation and the FAQ if you get stuck. -> 4. Search the forum if you need help or examples, method 1 (forum), method 2 (site), method 3 (Google). -> 5. Post your code on the forum in the "Ask for Help" section if you still run into problems (but read this first). -> 6. There is more AHK on autohotkey.net and the Wiki and there is an AHK IRC chat.


Jim Yuill
  • Members
  • 6 posts
  • Last active: Sep 21 2008 02:38 AM
  • Joined: 15 Sep 2008
.
I'm replying to "n-l-i-d"...

WOW! THANKS very much!!!

I'll try both of those code segments you posted here, and reply--hopefully tomorrow afternoon (Tuesday).

Jim

Jim Yuill
  • Members
  • 6 posts
  • Last active: Sep 21 2008 02:38 AM
  • Joined: 15 Sep 2008
.
I'm replying to n-l-i-d...

DUDE!!! Your code ROCKS!!!

Using your code, I got this to work. THANK YOU! I didn't know about the SendMessage functions.

FYI, I had to make just a few changes to your code:

* I couldn't get the EM_SETSEL to work. So instead, I sent down-arrow keys to move the list-box selection to the right place

* The string returned by EM_GETLINE is terminated by an ASCII carriage-control (ASCII 13), but it was easy to remove it.

The code is below. I'll post it to the script forum, should others need this function.


;;;;;;;;;;;;;
;
; PowerPoint hotkeys
;
;;;;;;;;;;;;;
;
; Test if PowerPoint is active:
IfWinActive Microsoft PowerPoint
{
;
;;;;;;;;;;;;;
; set F10 to be AHK for Paste Special -> Unformatted Text
;;;;;;;;;;;;;
;
F10::

; send keys to open "Paste Special" window:
Send !es!a

wantedOption := "Unformatted Text"
lineNumber := 0

; get number of lines in the "listbox"
SendMessage, (EM_GETLINECOUNT := 0xBA), 0, 0, REListBox20W1, ahk_class #32770
nrOfLinesInList := ErrorLevel 

;
; loop to find wantedOption, and select it
;
Loop %nrOfLinesInList%
{
   ; get contents of this line
   VarSetCapacity(thisLine, 100)
   SendMessage, (EM_GETLINE := 0xC4), A_Index-1, &thisLine, REListBox20W1, ahk_class #32770
   ; remove carriage-return from end of line
   StringLen length, thisline
   lineReturned := SubStr(thisLine,1,length-1)

   ; record current line number
   lineNumber++

   ; if it is the wantedOption...
   If (lineReturned = wantedOption)
   {
      ; if wantedOption is not the first option in the list-box: 
      ;   use down-arrow keys to move the selected option to wantedOption
      If (lineNumber > 1)
      {
          lineNumber--
          ControlFocus, REListBox20W1, ahk_class #32770
          SendInput !a{Down %lineNumber%}
      }

      ; click on OK
      ControlClick,Button1,,OK    

      ; quit the loop
      break
   ; end IF
   }    
; end loop
}

; if wantedOption not found, just return.  The "Paste Special" GUI will be left open.
; return for F10::
return
}
; return for PowerPoint section
return


Jim Yuill
  • Members
  • 6 posts
  • Last active: Sep 21 2008 02:38 AM
  • Joined: 15 Sep 2008
I found a bug in the code I just posted. Below is a corrected version.

The bug was: IfWinActive should have been #IfWinActive


;;;;;;;;;;;;;
;
; PowerPoint hotkeys
;
;;;;;;;;;;;;;
;
; Test if PowerPoint is active:
#IfWinActive, Microsoft PowerPoint
{
;
;;;;;;;;;;;;;
; set F10 to be AHK for Paste Special -> Unformatted Text
;;;;;;;;;;;;;
;
F10::

; send keys to open "Paste Special" window:
Send !es!a

wantedOption := "Unformatted Text"
lineNumber := 0

; get number of lines in the "listbox"
SendMessage, (EM_GETLINECOUNT := 0xBA), 0, 0, REListBox20W1, ahk_class #32770
nrOfLinesInList := ErrorLevel 

;
; loop to find wantedOption, and select it
;
Loop %nrOfLinesInList%
{
   ; get contents of this line
   VarSetCapacity(thisLine, 100)
   SendMessage, (EM_GETLINE := 0xC4), A_Index-1, &thisLine, REListBox20W1, ahk_class #32770
   ; remove carriage-return from end of line
   StringLen length, thisline
   lineReturned := SubStr(thisLine,1,length-1)

   ; record current line number
   lineNumber++

   ; if it is the wantedOption...
   If (lineReturned = wantedOption)
   {
      ; if wantedOption is not the first option in the list-box: 
      ;   use down-arrow keys to move the selected option to wantedOption
      If (lineNumber > 1)
      {
          lineNumber--
          ControlFocus, REListBox20W1, ahk_class #32770
          SendInput !a{Down %lineNumber%}
      }

      ; click on OK
      ControlClick,Button1,,OK    

      ; quit the loop
      break
   ; end IF
   }    
; end loop
}

; if wantedOption not found, just return.  The "Paste Special" GUI will be left open.
; return for F10::
return
}
; return for PowerPoint section
return