DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Capture the address window or file path to the clipboard with hotkey  (Read 18,679 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Capture the address window or file path to the clipboard with hotkey

I would like a software for

1. Capture the address of the selected active window to the clipboard with a definable hotkey
2. capture the file path selected to the clipboard with a definable hotkey




Best Regards

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
1. Capture the address of the selected active window to the clipboard with a definable hotkey

Since you have the active path displayed in the window's titlebar, you can do your first request like this:

Code: (autohotkey)
#q:: ; Win+Q, change to your liking.
{
    WinGetTitle, Clipboard, A
}
Return

2. capture the file path selected to the clipboard with a definable hotkey

The easiest way is probably:

Code: (autohotkey)
#c:: ; Win+C, change to your liking.
{
    Clipboard = %Clipboard%
}
Return

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
1. Capture the address of the selected active window to the clipboard with a definable hotkey

Since you have the active path displayed in the window's titlebar, you can do your first request like this:

Code: (autohotkey)
#q:: ; Win+Q, change to your liking.
{
    WinGetTitle, Clipboard, A
}
Return

2. capture the file path selected to the clipboard with a definable hotkey

The easiest way is probably:

Code: (autohotkey)
#c:: ; Win+C, change to your liking.
{
    Clipboard = %Clipboard%
}
Return


Running
I can't believe would be so simpleeeeeeeeeeeeeee

:-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
i am trying this first. But no results

Code
; 1. Capture the address of the selected active window to the clipboard with a definable hotkey

; Since you have the active path displayed in the window's titlebar, you can do your first request like this:

; Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
; Skwire
;   !#y:: ; no parece elegible ^#y en ctrl+Win+y, change to your liking. Pruebo con alt
	^!u:: ; 
    {
       WinGetTitle, Clipboard, A
    }
    Return

In the screenshots I selected the folder path, but the target is copy to the clipboard without it.
Only needed to select the windows folder.

I am doing something bad. Don't copy
I tried also win+1
but the clipboard have wrong.
It seems don't act the command
« Last Edit: June 27, 2012, 01:52 AM by Contro »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Repeating

Code
#q:: ; Win+Q, change to your liking.
    {
       WinGetTitle, Clipboard, A
    }
    Return

Go perfect

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Repeating

Code
#c:: ; Win+C, change to your liking.
    {
       Clipboard = %Clipboard%
    }
    Return

don't go

I don't understand

clipboard = %clipboard%  ; Convert any copied files, HTML, or other formatted text to plain text.

I position the cursor over one file.

By example :



After applying the script don't appear the clip in my Ditto Clipboard.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Try this:

Code: (autohotkey)
#c:: ; Win+C, change to your liking.
{
    SendInput, ^c
    ClipWait, 2
    Clipboard = %Clipboard%
}
Return

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
I'm not sure but I think what Contro is saying is:

a) If no file is selected, return the Window address field to the clipboard.
b) If a file is selected, return the full path of the file.

Feel free to ignore me if I'm wrong :)

Of course, with my non-knowledge of AutoHK you might have already answered the question, in which case feel free to  :trout:
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
I'm not sure but I think what Contro is saying is:

a) If no file is selected, return the Window address field to the clipboard.
b) If a file is selected, return the full path of the file.

Feel free to ignore me if I'm wrong :)

Of course, with my non-knowledge of AutoHK you might have already answered the question, in which case feel free to  :trout:

May be that what you are telling is what I must say.

;D

It's a good solution, because with one hotkey we can do all the tasks

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Try this:

Code: (autohotkey)
#c:: ; Win+C, change to your liking.
{
    SendInput, ^c
    ClipWait, 2
    Clipboard = %Clipboard%
}
Return

Running to try
Best Regards
:-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
A Strange thing. One time goes well. next time fails.

4wd is the best initial idea :

Possibilities with the assigned hotkey .
1. In the active window assigned hotkey copy the active window path to the clipboard
2. In the active window and one subfolder select copy the the subfolder path to the clipboard
3. In the active window and file select inside that folder or explorer window copy the file path to the clipboard.

:P

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
I did not write any of this, (except _ExClip function and set a hotkey), it was written by Ascend4ant and Melba23 over on the AutoIt forum.

Thank them if you want to thank someone.

The hotkey is set for Shift+Alt+C, edit the code to change it to what you like.

  • If nothing is selected, the Explorer path is clipped.
  • If something is selected, its full path is clipped.
  • If multiple somethings are selected, only the first one is returned.

Code: (autoit)
; http://www.autoitscript.com/forum/topic/89833-windows-explorer-current-folder/page__st__40#entry973904
#include <Array.au3>

HotKeySet('+!c', '_ExClip') ; Shift+Alt+C

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ComErrFunc")

While 1
	Sleep(100)
WEnd


Func _ExClip()
	$hExplr = WinActive("[REGEXPCLASS:(Explore|Cabinet)WClass]")
	If $hExplr <> '' Then
		$aSelection = _ExplorerWinGetSelectedItems($hExplr)
		If $aSelection[0] = 0 Then
			If StringLeft($aSelection[1], 2) <> '::' Then ClipPut($aSelection[1])
		Else
			ClipPut($aSelection[2])
		EndIf
	EndIf
EndFunc



; ==========================================================================================================================

; Func _ObjectSHFolderViewFromWin($hWnd)
;
; Returns an 'ShellFolderView' Object for the given Window handle
;
; Author: Ascend4nt, based on code by KaFu, klaus.s
; ==========================================================================================================================

Func _ObjectSHFolderViewFromWin($hWnd)
    If Not IsHWnd($hWnd) Then Return SetError(1,0,0)
    Local $oShell,$oShellWindows,$oIEObject,$oSHFolderView

    ; Shell Object
    $oShell=ObjCreate("Shell.Application")
    If Not IsObj($oShell) Then Return SetError(2,0,0)

;   Get a 'ShellWindows Collection' object
    $oShellWindows = $oShell.Windows()
    If Not IsObj($oShellWindows) Then Return SetError(3,0,0)

;   Iterate through the collection - each of type 'InternetExplorer' Object

    For $oIEObject In $oShellWindows
        If $oIEObject.HWND = $hWnd Then
            ; InternetExplorer->Document = ShellFolderView object
            $oSHFolderView=$oIEObject.Document
            If IsObj($oSHFolderView) Then Return $oSHFolderView
            Return SetError(4,0,0)
        EndIf
    Next

    Return SetError(-1,0,0)
EndFunc

; ==========================================================================================================================
; Func _ExplorerWinGetSelectedItems($hWnd)
;
;
; Author: klaus.s, KaFu, Ascend4nt (consolidation & cleanup, Path name simplification)
; ==========================================================================================================================

Func _ExplorerWinGetSelectedItems($hWnd)
    If Not IsHWnd($hWnd) Then Return SetError(1,0,'')
    Local $oSHFolderView
    Local $iSelectedItems,$iCounter=2,$aSelectedItems[2] = [0, ""]

    $oSHFolderView=_ObjectSHFolderViewFromWin($hWnd)
    If @error Then Return SetError(@error,0,'')

;   SelectedItems = FolderItems Collection object->Count
    $iSelectedItems = $oSHFolderView.SelectedItems.Count

    Dim $aSelectedItems[$iSelectedItems+2]  ; 2 extra -> 1 for count [0], 1 for Folder Path [1]

    $aSelectedItems[0]=$iSelectedItems
;   ShellFolderView->Folder->Self as 'FolderItem'->Path
    $aSelectedItems[1]=$oSHFolderView.Folder.Self.Path

;   ShellFolderView->SelectedItems = FolderItems Collection object
    $oSelectedFolderItems = $oSHFolderView.SelectedItems

#cs
    ; For ALL items in an Explorer Window (not just the selected ones):
    $oSelectedFolderItems = $oSHFolderView.Folder.Items
    ReDim $aSelectedItems[$oSelectedFolderItems.Count+2]
#ce

    For $oFolderItem In $oSelectedFolderItems
        $aSelectedItems[$iCounter] = $oFolderItem.Path
        $iCounter += 1
    Next

    Return SetExtended($iCounter-2,$aSelectedItems)
EndFunc   ;==>_ExplorerWinGetSelectedItems

Func _ComErrFunc($oError)
    ConsoleWrite("COM Error occurred:"  & @CRLF & _
        "Number: " & @TAB & $oError.number & @CRLF & _
        "Windescription:" & @TAB & $oError.windescription & @CRLF & _
        "Description is: " & @TAB & $oError.description & @CRLF & _
        "Source is: " & @TAB & $oError.source & @CRLF & _
        "Helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
        "Helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
        "Lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
        "Scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
        "Retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
EndFunc   ;==>_ComErrFunc
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: July 03, 2012, 02:30 PM by 4wd »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
I did not write any of this, (except _ExClip function and set a hotkey), it was written by Ascend4ant and Melba23 over on the AutoIt forum.

Thank them if you want to thank someone.

The hotkey is set for Shift+Alt+C, edit the code to change it to what you like.

  • If nothing is selected, the Explorer path is clipped.
  • If something is selected, its full path is clipped.
  • If multiple somethings are selected, only the first one is returned.

Code: (autoit)
; http://www.autoitscript.com/forum/topic/89833-windows-explorer-current-folder/page__st__40#entry973904
#include <Array.au3>

HotKeySet('+!c', '_ExClip') ; Shift+Alt+C

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ComErrFunc")

While 1
	Sleep(100)
WEnd


Func _ExClip()
	$hExplr = WinActive("[REGEXPCLASS:(Explore|Cabinet)WClass]")
	If $hExplr <> '' Then
		$aSelection = _ExplorerWinGetSelectedItems($hExplr)
		If $aSelection[0] = 0 Then
			If StringLeft($aSelection[1], 2) <> '::' Then ClipPut($aSelection[1])
		Else
			ClipPut($aSelection[2])
		EndIf
	EndIf
EndFunc



; ==========================================================================================================================

; Func _ObjectSHFolderViewFromWin($hWnd)
;
; Returns an 'ShellFolderView' Object for the given Window handle
;
; Author: Ascend4nt, based on code by KaFu, klaus.s
; ==========================================================================================================================

Func _ObjectSHFolderViewFromWin($hWnd)
    If Not IsHWnd($hWnd) Then Return SetError(1,0,0)
    Local $oShell,$oShellWindows,$oIEObject,$oSHFolderView

    ; Shell Object
    $oShell=ObjCreate("Shell.Application")
    If Not IsObj($oShell) Then Return SetError(2,0,0)

;   Get a 'ShellWindows Collection' object
    $oShellWindows = $oShell.Windows()
    If Not IsObj($oShellWindows) Then Return SetError(3,0,0)

;   Iterate through the collection - each of type 'InternetExplorer' Object

    For $oIEObject In $oShellWindows
        If $oIEObject.HWND = $hWnd Then
            ; InternetExplorer->Document = ShellFolderView object
            $oSHFolderView=$oIEObject.Document
            If IsObj($oSHFolderView) Then Return $oSHFolderView
            Return SetError(4,0,0)
        EndIf
    Next

    Return SetError(-1,0,0)
EndFunc

; ==========================================================================================================================
; Func _ExplorerWinGetSelectedItems($hWnd)
;
;
; Author: klaus.s, KaFu, Ascend4nt (consolidation & cleanup, Path name simplification)
; ==========================================================================================================================

Func _ExplorerWinGetSelectedItems($hWnd)
    If Not IsHWnd($hWnd) Then Return SetError(1,0,'')
    Local $oSHFolderView
    Local $iSelectedItems,$iCounter=2,$aSelectedItems[2] = [0, ""]

    $oSHFolderView=_ObjectSHFolderViewFromWin($hWnd)
    If @error Then Return SetError(@error,0,'')

;   SelectedItems = FolderItems Collection object->Count
    $iSelectedItems = $oSHFolderView.SelectedItems.Count

    Dim $aSelectedItems[$iSelectedItems+2]  ; 2 extra -> 1 for count [0], 1 for Folder Path [1]

    $aSelectedItems[0]=$iSelectedItems
;   ShellFolderView->Folder->Self as 'FolderItem'->Path
    $aSelectedItems[1]=$oSHFolderView.Folder.Self.Path

;   ShellFolderView->SelectedItems = FolderItems Collection object
    $oSelectedFolderItems = $oSHFolderView.SelectedItems

#cs
    ; For ALL items in an Explorer Window (not just the selected ones):
    $oSelectedFolderItems = $oSHFolderView.Folder.Items
    ReDim $aSelectedItems[$oSelectedFolderItems.Count+2]
#ce

    For $oFolderItem In $oSelectedFolderItems
        $aSelectedItems[$iCounter] = $oFolderItem.Path
        $iCounter += 1
    Next

    Return SetExtended($iCounter-2,$aSelectedItems)
EndFunc   ;==>_ExplorerWinGetSelectedItems

Func _ComErrFunc($oError)
    ConsoleWrite("COM Error occurred:"  & @CRLF & _
        "Number: " & @TAB & $oError.number & @CRLF & _
        "Windescription:" & @TAB & $oError.windescription & @CRLF & _
        "Description is: " & @TAB & $oError.description & @CRLF & _
        "Source is: " & @TAB & $oError.source & @CRLF & _
        "Helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
        "Helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
        "Lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
        "Scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
        "Retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
EndFunc   ;==>_ComErrFunc

I'll try and comment.
:-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
:P

Wonderful.
Wonderfullllllllllllllllllllllllllllllllllll

gabrielko

  • Participant
  • Joined in 2012
  • *
  • Posts: 1
Re: Capture the address window or file path to the clipboard with hotkey
« Reply #14 on: October 02, 2012, 04:41 PM »
This may or may not be significant, it's totally up to you to decide I really did get a quick fix with Long Path Tool. http://PathTooDeep.com ; :D

Original address: https://www.donationcoder.com/forum/index.php?topic=31443.0