AutoHotkey Community

It is currently May 26th, 2012, 10:33 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: September 3rd, 2009, 3:41 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Hi !

I have a syslistview32 control of a third party app and want to define a shortcut like :

Enter::doubleclick on highlighted item

Is there an easy way to do this (without dll apart from the microsoft ones) ?

I read the forum thoroughly and only came across "read text from list view"
topics.
Thanks in advance ! This would be damn useful !

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2009, 8:17 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Here you have something to play with :)

I can't get ControlClick to send a doubleclick, not sure why :?
Code:
VarSetCapacity(POINT,8) ;to recieve position

Gui,Add,ListView,r20 hwndsys AltSubmit gLaunch,test|auch
Loop 20
   LV_Add("",A_Index,A_Index)
Gui,Show

Gui +LastFound
hwnd:=WinExist()
Return

GuiClose:
ExitApp

Launch:
If A_GuiEvent=DoubleClick
   ToolTip % A_EventInfo
Return

Enter::
   ControlGetPos,x,y,,,,ahk_id %sys%
   SendMessage,TVM_GETITEM:=0x100c,-1,3,,ahk_id %sys%
   If ErrorLevel=4294967295
      Return
   item:=ErrorLevel+1
   SendMessage,LVM_GETITEMPOSITION:=0x1010,item,&POINT,,ahk_id %sys%
   x+=NumGet(POINT,0)
   y+=NumGet(POINT,4)
;~    ToolTip % y,0,0,2
   MouseClick,,% x,% y,2
   ;~ ControlClick, % "x" x " y" y,ahk_id %hwnd%,,,3, Pos ;,ahk_id %sys%,,,4
Return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2009, 8:47 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
@HotKeyIt : thanks indeed - I will play with it and post back

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2009, 8:59 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
This seems to work with Windows Explorer (thought Enter originally works as well) but this sends the doubleclick :)
But ControlClick will still not work :?

Includes RemoteBuf
Code:
ENTER::
   hwnd:=WinExist("A")
   chwnd=
   ControlGet,chwnd,HWND,,SysListView321,ahk_id %hwnd%
   If chwnd=
      Return
   ControlGetPos,x,y,,,,ahk_id %chwnd%
   SendMessage,TVM_GETITEM:=0x100c,-1,3,,ahk_id %chwnd%
   If ErrorLevel=4294967295
      Return
   VarSetCapacity(POINT,16) ;to recieve position
   item:=ErrorLevel+1
   size:=8
   RemoteBuf_Open(hPOINT, hwnd, size)
   SendMessage,LVM_GETITEMPOSITION:=0x1010,item,RemoteBuf_Get(hPOINT),SysListView321,ahk_id %hwnd%
   RemoteBuf_Read(hPOINT, POINT,size)
   RemoteBuf_Close(hPOINT)
   x+=NumGet(POINT,0)
   y+=NumGet(POINT,4)-5
   ToolTip % x " . " y "." item,0,0,2
   MouseClick,,% x,% y,2
;~    ControlClick, % "x" x " y" y,ahk_id %hwnd%,,,2 ;,ahk_id %chwnd%,,,4
Return


RemoteBuf_Open(ByRef H, hwnd, size) {
   static MEM_COMMIT=0x1000, PAGE_READWRITE=4

   WinGet, pid, PID, ahk_id %hwnd%
   hProc   := DllCall( "OpenProcess", "uint", 0x38, "int", 0, "uint", pid)
   IfEqual, hProc,0, return A_ThisFunc ">   Unable to open process (" A_LastError ")"
     
   bufAdr  := DllCall( "VirtualAllocEx", "uint", hProc, "uint", 0, "uint", size, "uint", MEM_COMMIT, "uint", PAGE_READWRITE)
   IfEqual, bufAdr,0, return A_ThisFunc ">   Unable to allocate memory (" A_LastError ")"
   VarSetCapacity(H, 12, 0 )
   NumPut( hProc,   H, 0)
   NumPut( size,   H, 4)
   NumPut( bufAdr, H, 8)
}

RemoteBuf_Close(ByRef H) {
   static MEM_RELEASE = 0x8000
   
   handle := NumGet(H, 0)
   IfEqual, handle, 0, return A_ThisFunc ">   Invalid remote buffer handle"
   adr    := NumGet(H, 8)

   r := DllCall( "VirtualFreeEx", "uint", handle, "uint", adr, "uint", 0, "uint", MEM_RELEASE)
   ifEqual, r, 0, return A_ThisFunc ">   Unable to free memory (" A_LastError ")"
   DllCall( "CloseHandle", "uint", handle )
   VarSetCapacity(H, 0 )
}


RemoteBuf_Read(ByRef H, ByRef pLocal, pSize, pOffset = 0){
   handle := NumGet( H, 0),   size:= NumGet( H, 4),   adr := NumGet( H, 8)
   IfEqual, handle, 0, return A_ThisFunc ">   Invalid remote buffer handle"   
   IfGreaterOrEqual, offset, %size%, return A_ThisFunc ">   Offset is bigger then size"

   VarSetCapacity( pLocal, pSize )
   return DllCall( "ReadProcessMemory", "uint", handle, "uint", adr + pOffset, "uint", &pLocal, "uint", size, "uint", 0 ), VarSetCapacity(pLocal, -1)
}


RemoteBuf_Write(Byref H, byref pLocal, pSize, pOffset=0) {
   handle:= NumGet( H, 0),   size := NumGet( H, 4),   adr := NumGet( H, 8)
   IfEqual, handle, 0, return A_ThisFunc ">   Invalid remote buffer handle"   
   IfGreaterOrEqual, offset, %size%, return A_ThisFunc ">   Offset is bigger then size"

   return DllCall( "WriteProcessMemory", "uint", handle,"uint", adr + pOffset,"uint", &pLocal,"uint", pSize, "uint", 0 )
}

RemoteBuf_Get(ByRef H, pQ="adr") {
   return pQ = "adr" ? NumGet(H, 8) : pQ = "size" ? NumGet(H, 4) : NumGet(H)
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 4th, 2009, 12:09 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Yes yes this second one works - needs some tweaking maybe for my needs (and a lot of reading) - thanks a lot ! The first one probably would work on GUIs only...
I 'll come back with the tweaked code

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 4th, 2009, 3:26 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Slightly modified to accommodate multiple treeviews, and only treeviews :
Code:
ENTER::
 hwnd:=WinExist("A")   ; this won't be needed as the shortcut will be in a "ifwinexist" hotkey command
controlgetfocus, cntrlNN ;,A
      if (RegExMatch(cntrlNN, "i)syslistview32")) {   ;if more than one syslistview32 are present
   
   ControlGet,chwnd,HWND,,%cntrlNN%,ahk_id %hwnd%
   If chwnd=   ;maybe superfluous
      Return
   ControlGetPos,x,y,,,,ahk_id %chwnd%
   SendMessage,TVM_GETITEM:=0x100c,-1,3,,ahk_id %chwnd%   ; could you explain this a bit ? why -1 for wparam ? what is the return value ?
   If ErrorLevel=4294967295
      Return
   VarSetCapacity(POINT,16) ;to receive position
   item:=ErrorLevel+1
   size:=8
   RemoteBuf_Open(hPOINT, hwnd, size)
   SendMessage,LVM_GETITEMPOSITION:=0x1010,item,RemoteBuf_Get(hPOINT),%cntrlNN%,ahk_id %hwnd%
   RemoteBuf_Read(hPOINT, POINT,size)
   RemoteBuf_Close(hPOINT)
   x+=NumGet(POINT,0)
   y+=NumGet(POINT,4)-5
   ToolTip % x " . " y "." item,0,0,2
   MouseClick,,% x,% y,2
;~    ControlClick, % "x" x " y" y,ahk_id %hwnd%,,,2 ;,ahk_id %chwnd%,,,4
   chwnd=
   }
Return
Thanks again - works like a charm and I think will be useful to many people :)

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 5th, 2009, 7:15 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Unfortunately the code above has a bug :( - when on the last item of the listview Enter clicks on other windows (???). I am not sure if I introduced the bug or was already in HotKeyIt's code. I'll test and post back.

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 5th, 2009, 7:58 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Does it produce the error for you in Windows Explorer, it works fine for me?
Code:
ENTER::
 hwnd:=WinExist("A")   ; this won't be needed as the shortcut will be in a "ifwinexist" hotkey command
controlgetfocus, cntrlNN ;,A
   if (RegExMatch(cntrlNN, "i)syslistview32")) {   ;if more than one syslistview32 are present
      ControlGet,chwnd,HWND,,%cntrlNN%,ahk_id %hwnd%
      ControlGetPos,x,y,,,,ahk_id %chwnd%
      SendMessage,LVM_GETITEM:=0x100c,-1,3,,ahk_id %chwnd%   ; http://msdn.microsoft.com/en-us/library/bb774953.aspx
      item:=ErrorLevel+1 ;Line number 0 based so +1 needed
      If ErrorLevel=4294967296
         Return
      VarSetCapacity(POINT,16) ;to receive position
      RemoteBuf_Open(hPOINT, hwnd, 8)
      SendMessage,LVM_GETITEMPOSITION:=0x1010,item,RemoteBuf_Get(hPOINT),%cntrlNN%,ahk_id %hwnd% ;http://msdn.microsoft.com/en-us/library/bb761048.aspx
      RemoteBuf_Read(hPOINT, POINT,size),RemoteBuf_Close(hPOINT)
      x+=NumGet(POINT,0)
      y+=NumGet(POINT,4)-10
      MouseClick,,% x,% y,2
      chwnd=
   }
Return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 5th, 2009, 8:22 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
You mean on the folders view of explorer ? EDIT : you meant Explorer's list of files and folders - works fine for me also EDIT2 : no doesn't - again in a folder (containing folders) sometimes (for instance if I press enter on another folder and then on the last one - or once it works, next time not, next time again works and so on) on the last folder I get the same behavior (x coordinate explodes)- only on the last folder and on details view. On list view works fine indeed. Arranged by name.
I am checking it on a 3rd party app EDIT : checked also on defraggler - same behavior
Basically the tooltip suddenly, on the last item of the list, displays a huge x coordinate - for instance jumping from 555 (same for all the other items) to 486136363 (!). Not the same number either and not same behavior - sometimes the window stays on focus sometimes another window receives focus (obviously was double-clicked by the script). If you cannot reproduce it then probably it's my weird app. Thanks anyway :)
The code I used :
Code:
~ENTER::   ;the tilde does not make any difference - I just added it for convenience
   hwnd:=WinExist("A")   ; this won't be needed as the shortcut will be in a "ifwinexist" hotkey command
controlgetfocus, cntrlNN ;,A
      if (RegExMatch(cntrlNN, "i)syslistview32")) {   ;if more than one syslistview32 are present
   
   ControlGet,chwnd,HWND,,%cntrlNN%,ahk_id %hwnd%
   If chwnd=
      Return
   ControlGetPos,x,y,,,,ahk_id %chwnd%
   SendMessage,TVM_GETITEM:=0x100c,-1,3,,ahk_id %chwnd%
   If ErrorLevel=4294967295
      Return
   VarSetCapacity(POINT,16) ;to receive position
   item:=ErrorLevel+1
   size:=8
   RemoteBuf_Open(hPOINT, hwnd, size)
   SendMessage,LVM_GETITEMPOSITION:=0x1010,item,RemoteBuf_Get(hPOINT),%cntrlNN%,ahk_id %hwnd%
   RemoteBuf_Read(hPOINT, POINT,size)
   RemoteBuf_Close(hPOINT)
   x+=NumGet(POINT,0)
   y+=NumGet(POINT,4)-10   ;changed this but no difference
   ToolTip % x " . " y "." item,0,0,2
   MouseClick,,% x,% y,2
;~    ControlClick, % "x" x " y" y,ahk_id %hwnd%,,,2 ;,ahk_id %chwnd%,,,4
   chwnd=
   }
Return

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Last edited by Mr_and_Mrs_D on September 5th, 2009, 9:19 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 5th, 2009, 8:53 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Checked it on defraggler - again weird behavior on last item - x coordinate jumps from 11 (same as for other items) to 91 to 16011 to 19839307 back to 11 etc Which numbers do i get depends on the speed I press enter :roll:

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2009, 2:53 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
HotKeyIt wrote:
I can't get ControlClick to send a doubleclick, not sure why :?
FYI, ControlClick fails to perform a double click ... (the short story: AutoHotkey sends two "single-clicks" not a double-click.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2009, 10:07 am 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Thanks Lexikos, I tested now on few lisviews, might work perfectly now ;)
Code:
ENTER::
 hwnd:=WinExist("A")   ; this won't be needed as the shortcut will be in a "ifwinexist" hotkey command
controlgetfocus, cntrlNN ;,A
   if (RegExMatch(cntrlNN, "i)syslistview32")) {   ;if more than one syslistview32 are present
      ControlGet,chwnd,HWND,,%cntrlNN%,ahk_id %hwnd%
;~       ControlGetPos,x,y,,,,ahk_id %chwnd%
      SendMessage,LVM_GETITEM:=0x100c,-1,3,,ahk_id %chwnd%   ; http://msdn.microsoft.com/en-us/library/bb774953.aspx
      item:=ErrorLevel+1 ;Line number 0 based so +1 needed
      If ErrorLevel=4294967296
         Return
      VarSetCapacity(POINT,16) ;to receive position
      RemoteBuf_Open(hPOINT, hwnd, 8)
      SendMessage,LVM_GETITEMPOSITION:=0x1010,item,RemoteBuf_Get(hPOINT),%cntrlNN%,ahk_id %hwnd% ;http://msdn.microsoft.com/en-us/library/bb761048.aspx
      RemoteBuf_Read(hPOINT, POINT,size),RemoteBuf_Close(hPOINT)
      x:=NumGet(POINT,0)
      y:=NumGet(POINT,4)-10
      PostMessage, 0x86, 0, ,, ahk_id %chwnd% ; WM_NCACTIVATE
      PostMessage, 0x201, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONDOWN
      PostMessage, 0x202, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONUP
      PostMessage, 0x203, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONDBLCLCK
      PostMessage, 0x202, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONUP
      chwnd=
   }
Return


Edit:
Small fix implemented, so it also works when mouse does not hover the listview

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2009, 7:09 pm 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Thanks ! Great improvement - but still in details view in explorer, the last item on the list produces a huge x-coordinate - check the tooltip in the code below. Also same problem in third party apps but not on all syslistviews - not sure yet why.
Code:
~ENTER::
 hwnd:=WinExist("A")   ; this won't be needed as the shortcut will be in a "ifwinexist" hotkey command
controlgetfocus, cntrlNN ;,A
   if (RegExMatch(cntrlNN, "i)syslistview32")) {   ;if more than one syslistview32 are present
      ControlGet,chwnd,HWND,,%cntrlNN%,ahk_id %hwnd%
;~       ControlGetPos,x,y,,,,ahk_id %chwnd%
      SendMessage,LVM_GETITEM:=0x100c,-1,3,,ahk_id %chwnd%   ; http://msdn.microsoft.com/en-us/library/bb774953.aspx
      item:=ErrorLevel+1 ;Line number 0 based so +1 needed
      If ErrorLevel=4294967296
         Return
      VarSetCapacity(POINT,16) ;to receive position
      RemoteBuf_Open(hPOINT, hwnd, 8)
      SendMessage,LVM_GETITEMPOSITION:=0x1010,item,RemoteBuf_Get(hPOINT),%cntrlNN%,ahk_id %hwnd% ;http://msdn.microsoft.com/en-us/library/bb761048.aspx
      RemoteBuf_Read(hPOINT, POINT,size),RemoteBuf_Close(hPOINT)
      x:=NumGet(POINT,0)
      y:=NumGet(POINT,4)-10
      PostMessage, 0x86, 0, ,, ahk_id %chwnd% ; WM_NCACTIVATE
      PostMessage, 0x201, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONDOWN
      PostMessage, 0x202, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONUP
      PostMessage, 0x203, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONDBLCLCK
      PostMessage, 0x202, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONUP
     tooltip x=%x% . y=%y%
      chwnd=
   }
Return

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2009, 9:43 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
I've got it ;)
Code:
~ENTER::
 hwnd:=WinExist("A")   ; this won't be needed as the shortcut will be in a "ifwinexist" hotkey command
controlgetfocus, cntrlNN ;,A
   if (RegExMatch(cntrlNN, "i)syslistview32")) {   ;if more than one syslistview32 are present
      ControlGet,chwnd,HWND,,%cntrlNN%,ahk_id %hwnd%
;~       ControlGetPos,x,y,,,,ahk_id %chwnd%
      SendMessage,LVM_GETITEMNEXT:=0x100c,-1,3,,ahk_id %chwnd%   ; http://msdn.microsoft.com/en-us/library/bb761057.aspx
      item:=ErrorLevel
      If ErrorLevel=4294967296
         Return
      VarSetCapacity(POINT,16) ;to receive position
      RemoteBuf_Open(hPOINT, hwnd, 8)
      SendMessage,LVM_GETITEMPOSITION:=0x1010,item,RemoteBuf_Get(hPOINT),%cntrlNN%,ahk_id %hwnd% ;http://msdn.microsoft.com/en-us/library/bb761048.aspx
      RemoteBuf_Read(hPOINT, POINT,size),RemoteBuf_Close(hPOINT)
      x:=NumGet(POINT,0)
      y:=NumGet(POINT,4)
      PostMessage, 0x86, 0, ,, ahk_id %chwnd% ; WM_NCACTIVATE
      PostMessage, 0x201, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONDOWN
      PostMessage, 0x202, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONUP
      PostMessage, 0x203, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONDBLCLCK
      PostMessage, 0x202, 0, X&0xFFFF | Y<<16,, ahk_id %chwnd% ; WM_LBUTTONUP
     tooltip x=%x% . y=%y% : %item%
      chwnd=
   }
Return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Last edited by HotKeyIt on September 7th, 2009, 8:09 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2009, 10:22 am 
Offline

Joined: December 19th, 2006, 2:17 pm
Posts: 164
Thanks so much !! I dedicate my 100th post to you !! Perfect :!:

As for the msdn links - I had checked them already, but still don't understand the LVITEM thing - shouldn't the wparam be 0 (while here it is -1) ?

I think I have to do (much) more googlework lol

Thanks again and I will be sure to credit you once I finish my script :)

_________________
XP SP3 Pro x32 / 7 x64 Pro - AHK 1.0.48.05


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, JSLover, Leef_me, Miguel, rbrtryn and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group