Monamo Posted February 3, 2009 Share Posted February 3, 2009 For those that typically have "Hide file extensions for known file types" disabled in Windows XP, it's an annoyance (at least for me) that using the Windows hotkey "F2" to rename files manually causes you to have to take care to avoid clearing the file extension.Lifehacker had an AHK script (they're big on AHK) to address this, and I've converted it to AutoIt for those that might want to use it.My recommendation would be to include it inside of any "persistent" scripts that you have running all the time (say, inside of a system monitoring script, whatever) since it seems kind of excessive to have a compiled version of this running standalone. Unless, of course, you don't have any other "always on" scripts.Hope it's of use to some of you out there.expandcollapse popupHotKeySet("{F2}", "_AnalyzeRename") While 1 Sleep(10) WEnd Func _AnalyzeRename() HotKeySet("{F2}"); prevent infinite loop gotcha Send("{F2}") If (_WinGetClass(WinGetTitle('')) = "CabinetWClass") Or (_WinGetClass(WinGetTitle('')) = "Progman") Then $oldClipboard = ClipGet() Sleep(100) Send("^c") $sFilename = ClipGet() $iExtPosition = StringInStr($sFilename, ".", 0, -1) If $iExtPosition <> 0 Then $iPosition = StringLen($sFilename) - $iExtPosition $i = 0 Send("^{HOME}") Do Send("+{RIGHT}") $i += 1 Until $i = ($iExtPosition - 1) Send("{SHIFTDOWN}{SHIFTUP}") EndIf ClipPut($oldClipboard) EndIf HotKeySet("{F2}", "_AnalyzeRename"); re-enable hotkey EndFunc Func _WinGetClass($hWnd) ; credit = SmOke_N from post http://www.autoitscript.com/forum/index.php?showtopic=41622&view=findpost&p=309799 If IsHWnd($hWnd) = 0 And WinExists($hWnd) Then $hWnd = WinGetHandle($hWnd) Local $aGCNDLL = DllCall('User32.dll', 'int', 'GetClassName', 'hwnd', $hWnd, 'str', '', 'int', 4095) If @error = 0 Then Return $aGCNDLL[2] Return SetError(1, 0, '') EndFunc - MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup] Link to comment Share on other sites More sharing options...
ProgAndy Posted February 3, 2009 Share Posted February 3, 2009 (edited) i wrote one, too for the german forum: http://www.autoit.de/index.php?page=Thread...69756#post69756(no clipboard used and no send commands)#include <WinAPI.au3> While 1 $ActiveWin = WinGetHandle("") $Win = _WinAPI_GetClassName($ActiveWin) If $Win = "CabinetWClass" Or $Win = "ExploreWClass" Then $Class = ControlGetFocus($ActiveWin) If StringRegExp($Class,"\AEdit\d+\Z") Then $EditHandle = ControlGetHandle($ActiveWin,"",$Class) $ParentClass = _WinAPI_GetClassName(_WinAPI_GetParent($EditHandle)) If $ParentClass = "SysListView32" Then $text = ControlGetText($ActiveWin,"",$Class) $LetzterPunkt = StringInStr($text,".",1,-1) If $LetzterPunkt Then _SendMessage($EditHandle,0xB1,0,$LetzterPunkt-1,0,"dword","dword") ; 0xB1 = EM_SETSEL Do Sleep(100) Until ControlGetFocus("") <> $Class EndIf EndIf EndIf EndIf Sleep(100) WEnd Edited February 3, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
UEZ Posted February 3, 2009 Share Posted February 3, 2009 That would be nice also in Firefox when you rename the filename when downloading a file.... UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 23, 2009 Share Posted April 23, 2009 Can I play? #include <String.au3> #include <WinAPI.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile If $sClass = "ExploreWClass" Or $sClass = "CabinetWClass" Or $sClass = "Progman" Then HotKeySet("{F2}") Send("{F2}") $sFile = _WinAPI_GetWindowText(ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]"))) Local $i = StringLen($sFile) - StringInStr($sFile, ".", 0, -1) + 1 If $i < StringLen($sFile) Then Send("{SHIFTDOWN}" & _StringRepeat("{LEFT}", $i) & "{SHIFTUP}") HotKeySet("{F2}", "_VistaRename") EndIf EndFunc No clipboard. I was trying to make this concise. I probably missed something ... WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
ResNullius Posted April 23, 2009 Share Posted April 23, 2009 Can I play? #include <String.au3> #include <WinAPI.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile If $sClass = "ExploreWClass" Or $sClass = "CabinetWClass" Or $sClass = "Progman" Then HotKeySet("{F2}") Send("{F2}") $sFile = _WinAPI_GetWindowText(ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]"))) Local $i = StringLen($sFile) - StringInStr($sFile, ".", 0, -1) + 1 If $i < StringLen($sFile) Then Send("{SHIFTDOWN}" & _StringRepeat("{LEFT}", $i) & "{SHIFTUP}") HotKeySet("{F2}", "_VistaRename") EndIf EndFunc No clipboard. I was trying to make this concise. I probably missed something ... WBD@WideBoyDixon If I may: #include <String.au3> #include <WinAPI.au3> #include <GuiEdit.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() HotKeySet("{F2}") Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile If $sClass = "ExploreWClass" Or $sClass = "CabinetWClass" Or $sClass = "Progman" Then Send("{F2}") $hFileEdit = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) $sFile = _WinAPI_GetWindowText(ControlGetHandle("[ACTIVE]", "", $hFileEdit)) Local $i = StringLen($sFile) - StringInStr($sFile, ".", 0, -1) + 1 If $i < StringLen($sFile) Then _GUICtrlEdit_SetSel($hFileEdit, 0, StringLen($sFile) - $i) EndIf Else Send("{F2}"); if some other window need to pass the F2 through EndIf HotKeySet("{F2}", "_VistaRename") EndFunc No SendKey Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 23, 2009 Share Posted April 23, 2009 @WideBoyDixon If I may: #include <String.au3> #include <WinAPI.au3> #include <GuiEdit.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() HotKeySet("{F2}") Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile If $sClass = "ExploreWClass" Or $sClass = "CabinetWClass" Or $sClass = "Progman" Then Send("{F2}") $hFileEdit = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) $sFile = _WinAPI_GetWindowText(ControlGetHandle("[ACTIVE]", "", $hFileEdit)) Local $i = StringLen($sFile) - StringInStr($sFile, ".", 0, -1) + 1 If $i < StringLen($sFile) Then _GUICtrlEdit_SetSel($hFileEdit, 0, StringLen($sFile) - $i) EndIf Else Send("{F2}"); if some other window need to pass the F2 through EndIf HotKeySet("{F2}", "_VistaRename") EndFunc No SendKey You have me at a disadvantage sir with your ninja coding skillz (is that how the yoof of today say it?). Totally forgot about passing through F2 to other windows However, since I'm here now, some notes: [1] I did notice that $hFileEdit is already a window handle so _WinAPI_GetWindowText($hFileEdit) should be sufficient shouldn't it? [2] The calculation of $i should be re-worked for using _GUICtrlEdit_SetSel(): Local $i = StringInStr($sFile, ".", 0, -1) If $i > 1 Then _GUICtrlEdit_SetSel($hFileEdit, 0, $i - 1) [3] Actually, I quite liked the "sweep" of sending {LEFT}. Sad really WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
ResNullius Posted April 24, 2009 Share Posted April 24, 2009 (edited) You have me at a disadvantage sir with your ninja coding skillz (is that how the yoof of today say it?). Totally forgot about passing through F2 to other windows However, since I'm here now, some notes: [1] I did notice that $hFileEdit is already a window handle so _WinAPI_GetWindowText($hFileEdit) should be sufficient shouldn't it? [2] The calculation of $i should be re-worked for using _GUICtrlEdit_SetSel(): Local $i = StringInStr($sFile, ".", 0, -1) If $i > 1 Then _GUICtrlEdit_SetSel($hFileEdit, 0, $i - 1) [3] Actually, I quite liked the "sweep" of sending {LEFT}. Sad really WBDOK, so here's the most concise version I can come up with (for now). And look: I got rid of one more Send() ! While I too liked the visual appeal of the left "sweep", I really like to avoid Send() whenever I can. #include <String.au3> #include <WinAPI.au3> #include <GuiEdit.au3> #include <GuiListView.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() HotKeySet("{F2}") Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile If $sClass = "ExploreWClass" Or $sClass = "CabinetWClass" Or $sClass = "Progman" Then $hListView = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) _GUICtrlListView_EditLabel($hListView, _GUICtrlListView_GetNextItem($hListView)) ;$hFileEdit = _GUICtrlListView_GetEditControl($hListView) ;hmmm, GUICtrlEdit_GetText & _GUICtrlEdit_SetSel doesn't seem to work with this $hFileEdit = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) $sFile = _GUICtrlEdit_GetText($hFileEdit) $i = StringInStr($sFile, ".", 0, -1) - 1 _GUICtrlEdit_SetSel($hFileEdit, 0, $i) Else Send("{F2}"); if some other window need to pass the F2 through EndIf HotKeySet("{F2}", "_VistaRename") EndFunc ;==>_VistaRename Edit: On reviewing this entire thread, it appears my method is not so different from ProgAndy's in post #2... ( http://www.autoitscript.com/forum/index.ph...st&p=638874 ) Edited April 24, 2009 by ResNullius Link to comment Share on other sites More sharing options...
ResNullius Posted April 24, 2009 Share Posted April 24, 2009 (edited) Mo' conciser:#include <String.au3> #include <WinAPI.au3> #include <GuiEdit.au3> #include <GuiListView.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() HotKeySet("{F2}") Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")) Local $sFile, $hListView, $hFileEdit, $iDotPos If $sClass = "ExploreWClass" Or $sClass = "CabinetWClass" Or $sClass = "Progman" Then $hListView = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) $hFileEdit = _GUICtrlListView_EditLabel($hListView, _GUICtrlListView_GetNextItem($hListView)) $sFile = _GUICtrlEdit_GetText($hFileEdit) $iDotPos = StringInStr($sFile, ".", 0, -1) - 1 _GUICtrlEdit_SetSel($hFileEdit, 0, $iDotPos) Else Send("{F2}");if some other window need to pass the F2 through EndIf HotKeySet("{F2}", "_VistaRename") EndFunc;==>_VistaRenameEdit: Added missing local variable declarations Edited April 24, 2009 by ResNullius Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 24, 2009 Share Posted April 24, 2009 Ah but you broke my ability to use F2 in the TreeView in Explorer. I'm settling on ... #include <String.au3> #include <WinAPI.au3> #include <GuiEdit.au3> #include <GuiListView.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() HotKeySet("{F2}") Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile, $hListView, $hFileEdit If StringInstr("|ExploreWClass|CabinetWClass|Progman|", "|" & $sClass & "|") > 0 Then $hActiveControl = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) If _WinAPI_GetClassName($hActiveControl) = "SysListView32" Then $hFileEdit = _GUICtrlListView_EditLabel($hActiveControl, _GUICtrlListView_GetNextItem($hActiveControl)) $sFile = _GUICtrlEdit_GetText($hFileEdit) _GUICtrlEdit_SetSel($hFileEdit, 0, StringInStr($sFile, ".", 0, -1) - 1) Else Send("{F2}") EndIf Else Send("{F2}") EndIf HotKeySet("{F2}", "_VistaRename") EndFunc ;==>_VistaRename WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
ResNullius Posted April 24, 2009 Share Posted April 24, 2009 Ah but you broke my ability to use F2 in the TreeView in Explorer. I'm settling on ... #include <String.au3> #include <WinAPI.au3> #include <GuiEdit.au3> #include <GuiListView.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() HotKeySet("{F2}") Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile, $hListView, $hFileEdit If StringInstr("|ExploreWClass|CabinetWClass|Progman|", "|" & $sClass & "|") > 0 Then $hActiveControl = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) If _WinAPI_GetClassName($hActiveControl) = "SysListView32" Then $hFileEdit = _GUICtrlListView_EditLabel($hActiveControl, _GUICtrlListView_GetNextItem($hActiveControl)) $sFile = _GUICtrlEdit_GetText($hFileEdit) _GUICtrlEdit_SetSel($hFileEdit, 0, StringInStr($sFile, ".", 0, -1) - 1) Else Send("{F2}") EndIf Else Send("{F2}") EndIf HotKeySet("{F2}", "_VistaRename") EndFunc ;==>_VistaRename WBDAgreed good sir. Like the way you "concised" up my $iDotPos into the _SetSel. Cheers! Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted April 24, 2009 Share Posted April 24, 2009 (edited) I want to play! #include <String.au3> #include <WinAPI.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <GuiTreeView.au3> HotKeySet("{F2}", "_VistaRename") While 1 Sleep(100) WEnd Func _VistaRename() HotKeySet("{F2}") Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile, $hListView, $hFileEdit If StringInstr("|ExploreWClass|CabinetWClass|Progman|", "|" & $sClass & "|") > 0 Then $hActiveControl = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) If _WinAPI_GetClassName($hActiveControl) = "SysListView32" Then $hFileEdit = _GUICtrlListView_EditLabel($hActiveControl, _GUICtrlListView_GetNextItem($hActiveControl)) $sFile = _GUICtrlEdit_GetText($hFileEdit) _GUICtrlEdit_SetSel($hFileEdit, 0, StringInStr($sFile, ".", 0, -1) - 1) ElseIf _WinAPI_GetClassName($hActiveControl) = "SysTreeView32" Then $hFileEdit = _GUICtrlTreeView_EditText($hActiveControl, _GUICtrlTreeView_GetSelection($hActiveControl)) $sFile = _GUICtrlEdit_GetText($hFileEdit) _GUICtrlEdit_SetSel($hFileEdit, 0, StringInStr($sFile, ".", 0, -1) - 1) Else Send("{F2}") EndIf Else Send("{F2}") EndIf HotKeySet("{F2}", "_VistaRename") EndFunc ;==>_VistaRename This is for renaming zip files in the treeview. Only problem with it, is after the edit, I loose it's ability to expand/collapse. Haven't found a fix for that yet. Edit: Apparently, that also happens without the script running for me, so the script is fine as is. Edited April 24, 2009 by SkinnyWhiteGuy Link to comment Share on other sites More sharing options...
goldenix Posted April 24, 2009 Share Posted April 24, 2009 (edited) @WideBoyDixon Your script works like a charm. thank you. Edited April 24, 2009 by goldenix My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
Mat Posted April 24, 2009 Share Posted April 24, 2009 (edited) Before I try to spoil everything, thankyou wideboydixon + resnullius, not only for the script, but also the entertainment value. It reminds us all how valuable competition is to us all. brings prices down. all have errors, but they can't be solved without breaking the whole idea of a small script... 1) You can rename folders to "Folder.ext". It thinks its a file, and mucks up by acting as it would for a file (This was me deliberately trying to be a pain) 2) haven't got into the context menu > rename yet. I tried, I failed. nowhere in the shell for * or file, neither was it mentioned in the CLSID for file. Tried looking at various explorer related keys, and lastly made a last ditch attempt to search the whole registry for "Rena&me", still nothing. I dont know how you could do it that way then, Possibly editing explorer.exe, but thats not my cup of tea or coffee. 3) Extensions with dots in them (once again, me being an asshole) 4) Do you actually use string.au3 anywhere? That looks like a waste of space to me... 5) you could streamline it further, picking out includes etc. but that gets bit pointless as its a small script, and unless you're compiling it won't make much size difference. I am being very annoying with some of those, redirecting would be nice though if it was possible... had a quick look in reshacker, though I don't know what I'm looking for really. MDiesel Edited April 24, 2009 by mdiesel AutoIt Project Listing Link to comment Share on other sites More sharing options...
coolz Posted August 6, 2010 Share Posted August 6, 2010 (edited) Sorry to revive this; found none related. Looking to use WBDs code and resolve some of Mat's issues. How would I code multiple presses of F2 while renaming to switch between selections? For example (red indicates highlighted text): $sFile = "sample.txt.bak" Press F2 - sample.txt.bak Press F2 again - sample.txt.bak Press F2 again - sample.txt.bak Press F2 again - sample.txt.bak My slow, broken, ugly solution which changes the occurrence number for StringInStr: Func _VistaRename() HotKeySet("{F2}") Local $i = 0 Local $sClass = _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")), $sFile, $hListView, $hFileEdit If StringInstr("|ExploreWClass|CabinetWClass|Progman|", "|" & $sClass & "|") > 0 Then $hActiveControl = ControlGetHandle("[ACTIVE]", "", ControlGetFocus("[ACTIVE]")) If _WinAPI_GetClassName($hActiveControl) = "SysListView32" Then $hFileEdit = _GUICtrlListView_EditLabel($hActiveControl, _GUICtrlListView_GetNextItem($hActiveControl)) $sFile = _GUICtrlEdit_GetText($hFileEdit) $split = StringSplit($sFile, ".") $occur = $split[0] Do _GUICtrlEdit_SetSel($hFileEdit, 0, StringInStr($sFile, ".", 0, -$i) - 1) Sleep(100) if _isPressed("71", $dll) Then $i = $i+1 ;if {F2} Until $i > $occur Else Send("{F2}") EndIf Else Send("{F2}") EndIf HotKeySet("{F2}", "_VistaRename") EndFunc ;==>_VistaRename Please pardon my lack of experience (none). Help is appreciated! Edited August 6, 2010 by coolz Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now