<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: ButtonBar eXtended помощь Total Commander-сообществу]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=13524&amp;type=atom" />
	<updated>2018-03-09T09:33:03Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=13524</id>
		<entry>
			<title type="html"><![CDATA[AHK: ButtonBar eXtended помощь Total Commander-сообществу]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=123992#p123992" />
			<content type="html"><![CDATA[<p>Есть очень востребованная среди сборщиков Total Commander утилита:<br /><a href="http://www.ghisler.ch/board/viewtopic.php?t=20274">ButtonBar eXtended</a></p><p>Утилита написана уже в далёком 2011 и имеет пару проблем с UAC:<br />1) Утилита не передаёт повышение прав программе которую запускает. То есть если ButtonBar eXtended запустить от Администратора, то программа которую запустит утилита не получает команду также запуститься от Администратора.<br />2) Утилита ищет Usercmd.ini в корневой папке Total Commander, но будучи запущенной с повышением прав, она его там не находит.</p><p>Обе эти проблемы решаются если запускать TC от имени администратора.</p><p>Просьба подправить исходный код утилиты:<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>; &quot;ButtonBar eXtended&quot; for Total Commander
; Version: 2.3
; Freeware by Samuel Plentz - www.SamuelPlentz.de.vu

; ### --------------------------------------------------------------------------
; ### get current keystates of Ctrl, Alt &amp; Shift and read parameters

#NoTrayIcon
#SingleInstance off
SetBatchLines -1
AutoTrim,Off

Getkeystate,Keystate_Ctrl ,Ctrl
Getkeystate,Keystate_Alt  ,Alt
Getkeystate,Keystate_Shift,Shift

Quote=&quot;
Parameter_1=%1%
Parameter_2E=%2%
Parameter_3E=%3%
StringLower,Parameter_1L,1
transform,Parameter_2,deref,%Parameter_2E%
transform,Parameter_3,deref,%Parameter_3E%

; ##############################################################################
; ### convert &quot;ButtonBar&quot; to &quot;ButtonBar eXtended&quot;

if(Parameter_1L==&quot;-c&quot; || Parameter_1L==&quot;-d&quot;){
; # check if Parameter_2 is valid and get NewFilename --------------------------
 IniRead,ButtonCount,%Parameter_2%,Buttonbar,Buttoncount,0
	if(!RegExMatch(Parameter_2,&quot;i)\.bar$&quot;) || !FileExist(Parameter_2) || ButtonCount==0){
		msgbox,16,Error: Wrong Parameters,A valid &quot;ButtonBar&quot; is needed to convert it to a &quot;ButtonBar eXtended&quot;.`nParameter 1: &quot;%Parameter_1%&quot;`nParameter 2: &quot;%Parameter_2E%&quot;
		return
	}
 SplitPath,Parameter_2,Parameter_2Name,tFilePath,,UserCmdSection
 NewFilename=BBX_%Parameter_2Name%
 if(tFilePath!=&quot;&quot;){
		NewFilename=%tFilePath%\%NewFilename%
	}
	NewFilenameCache=NewFilename
	StringTrimRight,NewFilenameCache,NewFilenameCache,3
	NewFilenameCache=%NewFilenameCache%br2
	FileDelete,%NewFilename%
	FileDelete,%NewFilenameCache%
	
; # delete all old user commands for this &quot;ButtonBar eXtended&quot; -----------------
 StringReplace,UserCmdSection,UserCmdSection,%A_Space%,_,1
 StringReplace,UserCmdSection,UserCmdSection,-,_,1
 StringReplace,UserCmdSection,UserCmdSection,=,_,1
 UserCmdSection=em_BBX_%UserCmdSection%&gt;
	UserCmdFile := LocationUserCmdFile()
	WinCmdFile := LocationWinCmdFile()
	FileRead,UserCmdContent,%UserCmdFile%
	Loop,parse,UserCmdContent,`n,`r
	{
		if(1==InStr(A_LoopField,&quot;[&quot; . UserCmdSection) || (1==InStr(A_LoopField,&quot;[em_BBX_&quot;) &amp;&amp; 0==InStr(A_LoopField,&quot;&gt;&quot;))){
			StringTrimLeft,currentSection,A_LoopField,1
			StringTrimRight,currentSection,currentSection,1
			IniDelete,%UserCmdFile%,%currentSection%
		}
	}

; # read all commands from the &quot;ButtonBar&quot; -------------------------------------
 A_ScriptFullPathE=%A_ScriptFullPath%
 A_ScriptDirE=%A_ScriptDir%
 Loop,%ButtonCount%
 {
  ReadCommand(Parameter_2,A_Index)
  Command := cmd%A_Index%
  SplitPath,Command,tFilename
  StringReplace,tFilename,tFilename,&quot;,,All
  
; change convert button to edit button
  if(tFilename==A_ScriptName &amp;&amp; InStr(param%A_Index%,Parameter_2Name) &amp;&amp; (InStr(param%A_Index%,&quot;-d&quot;) || InStr(param%A_Index%,&quot;-c&quot;))){
  	A_ScriptFullPathE := cmd%A_Index%
  	SplitPath,A_ScriptFullPathE,,A_ScriptDirE
  	A_ScriptDirE=%A_ScriptDirE%\
  	cmd%A_Index% := Parameter_2E
  	param%A_Index% := &quot;&quot;
  	path%A_Index% := &quot;&quot;
  	menu%A_Index% := &quot;Edit this &quot; . Quote . &quot;ButtonBar eXtended&quot; . Quote
  }
 }

; # convert all commands from the &quot;ButtonBar&quot; ----------------------------------
 OutputButtonbarCount=0
 OutputUserCmdCount=0
 Mode=0
 Loop,%ButtonCount%
 {
 	nextIndex := A_Index+1
 	if(RegExMatch(menu%nextIndex%,&quot;i)(^[2-5]?(c|a|s|ca|cs|as|cas)$|^[2-5]$|^m$)&quot;)){

; start of an &quot;eXtended command&quot;
 		if(Mode==0){
  		Mode=1
 			OutputButtonbarCount++
 			OutputUserCmdCount++
    OutputUserCmdState=
   	OutputUserCmdStateCount=1
    WriteNewCommand(NewFilename,&quot;Buttonbar&quot;,OutputButtonbarCount,A_ScriptFullPathE,A_ScriptDirE,UserCmdSection . OutputUserCmdCount,button%A_Index%,0,menu%A_Index%)
 			menu%A_Index% := &quot;&quot;
    WriteCommand(UserCmdFile,A_Index,UserCmdSection . OutputUserCmdCount . &quot;_&quot; . OutputUserCmdState . &quot;_&quot; . OutputUserCmdStateCount,&quot;&quot;)
    continue
 		}
		}else{
			Mode=0
		}
	
; &quot;eXtended command&quot; continues
 	if(RegExMatch(menu%A_Index%,&quot;i)(^[2-5]?(c|a|s|ca|cs|as|cas)$|^[2-5]$|^m$)&quot;)){
 		if(RegExMatch(menu%A_Index%,&quot;i)^m$&quot;)){
 			OutputUserCmdStateCount++
 		 menu%A_Index% := &quot;&quot;
			}else{
 			StringLower,OutputUserCmdState,menu%A_Index%
 			if menu%A_Index% is not lower
 			 menu%A_Index% := &quot;w&quot;
 			else
 			 menu%A_Index% := &quot;&quot;
   	OutputUserCmdStateCount=1
 		}

   WriteCommand(UserCmdFile,A_Index,UserCmdSection . OutputUserCmdCount . &quot;_&quot; . OutputUserCmdState . &quot;_&quot; . OutputUserCmdStateCount,&quot;&quot;)
   continue		
  }

; ahk command
  if(1==InStr(cmd%A_Index%,&quot;ahk_&quot;)){
  	OutputButtonbarCount++
 		OutputUserCmdCount++
   WriteNewCommand(NewFilename,&quot;Buttonbar&quot;,OutputButtonbarCount,A_ScriptFullPathE,A_ScriptDirE,UserCmdSection . OutputUserCmdCount,button%A_Index%,0,menu%A_Index%)
 		menu%A_Index% := &quot;&quot;
   WriteCommand(UserCmdFile,A_Index,UserCmdSection . OutputUserCmdCount . &quot;__1&quot;,&quot;&quot;)
   continue
  }

; simple command
  OutputButtonbarCount++
  WriteCommand(NewFilename,A_Index,&quot;Buttonbar&quot;,OutputButtonbarCount)
 }
 IniWrite,%OutputButtonbarCount%,%NewFilename%,Buttonbar,Buttoncount
 
; make the &quot;ButtonBar eXtended&quot; the default if &quot;-d&quot; was used
 if(Parameter_1L==&quot;-d&quot; &amp;&amp; FileExist(WinCmdFile)){
 	IniWrite,%NewFilename%,%WinCmdFile%,Buttonbar,Buttonbar
 }
 OutputUserCmdCount++
 if(Parameter_3!=&quot;&quot;){
  WriteNewCommand(UserCmdFile,UserCmdSection . OutputUserCmdCount,&quot;&quot;,&quot;OPENBAR&quot;,&quot;&quot;,Parameter_3,&quot;&quot;,0,&quot;&quot;)
 }else{
  WriteNewCommand(UserCmdFile,UserCmdSection . OutputUserCmdCount,&quot;&quot;,&quot;OPENBAR&quot;,&quot;&quot;,NewFilename,&quot;&quot;,0,&quot;&quot;)
 }
 Command=%UserCmdSection%%OutputUserCmdCount%
 EM_Command(Command)
 ExitApp
}



; ##############################################################################
; ### execute a command in the &quot;ButtonBar eXtended&quot;

if(Parameter_1!=&quot;&quot;){
	UserCmdFile := LocationUserCmdFile()
	MouseState := GetMouseButton()
	Mode_CAS=%MouseState%
	if(Keystate_Ctrl==&quot;D&quot;){
	 Mode_CAS=%Mode_CAS%c
	}
	if(Keystate_Alt==&quot;D&quot;){
	 Mode_CAS=%Mode_CAS%a
	}
	if(Keystate_Shift==&quot;D&quot;){
	 Mode_CAS=%Mode_CAS%s
	}

; use default command if current keyboard modifiers are not available
 if(Mode_CAS!=&quot;&quot;){
 	IniRead,value,%UserCmdFile%,%Parameter_1%_%Mode_CAS%_1,cmd,%A_Space%

; when there is no action defined for middlemousebutton it reacts like Ctrl
 	if(value==&quot;&quot;){
 		if(Mode_CAS==&quot;3&quot;){
  		Mode_CAS=c
 		}else{
  		Mode_CAS=%MouseState%
 		}
 	}else{

; wait for modifier releases if necessary
  	IniRead,value,%UserCmdFile%,%Parameter_1%_%Mode_CAS%_1,menu,%A_Space%
	 	if(value==&quot;w&quot;){
    Loop{
     Getkeystate,Keystate_Ctrl ,Ctrl
     Getkeystate,Keystate_Alt  ,Alt
     Getkeystate,Keystate_Shift,Shift
     if(Keystate_Ctrl!=&quot;D&quot; &amp;&amp; Keystate_Alt!=&quot;D&quot; &amp;&amp; Keystate_Shift!=&quot;D&quot;){
      break
     }
    }
   }
 	}
 }

; execute all according commands
 Loop
	{
 	IniRead,Command,%UserCmdFile%,%Parameter_1%_%Mode_CAS%_%A_Index%,cmd,%A_Space%
 	if(Command==&quot;&quot;){
 		break
 	}

; run custom ahk commands
 	StringLower,Command,Command
  if(1==InStr(Command,&quot;ahk_&quot;)){
  	IniRead,Parameter_ahk,%UserCmdFile%,%Parameter_1%_%Mode_CAS%_%A_Index%,param,%A_Space%
  	if(Command==&quot;ahk_sleep&quot;){
  		Sleep,%Parameter_ahk%
  		continue
  	}
  	if(Command==&quot;ahk_sendinput&quot;){
  		SendInput,%Parameter_ahk%
  		continue
  	}
  	continue
  }

; run normal em_commands
  Command=%Parameter_1%_%Mode_CAS%_%A_Index%
	 EM_Command(Command)
 }
 ExitApp
}

ExitApp

; ##############################################################################
; ##############################################################################
; ##############################################################################



; ### --------------------------------------------------------------------------
; ### get location of &quot;usercmd.ini&quot; (use CustomUsercmd if set in ini)

LocationUserCmdFile()
{
	IniRead,tFileName,ButtonBar eXtended.ini,ButtonBar eXtended,CustomUsercmd,-
	if(tFileName!=&quot;-&quot;){
		transform,tFileName,deref,%tFileName%
	 return tFileName
	}
 EnvGet,LocationWinCmdFile,COMMANDER_INI
 SplitPath,LocationWinCmdFile,,tFilePath
 tFilename=usercmd.ini
 if(tFilePath!=&quot;&quot;){
		tFilename=%tFilePath%\%tFilename%
	}
	return tFilename
}

LocationWinCmdFile()
{
 EnvGet,LocationWinCmdFile,COMMANDER_INI
	return LocationWinCmdFile
}

; ### --------------------------------------------------------------------------
; ### read command into an array

ReadCommand(Filename,ArrayNr)
{
	global
 IniRead,cmd%ArrayNr%   ,%Filename%,Buttonbar,cmd%ArrayNr%   ,%A_Space%
 cmd%ArrayNr%    := RegExReplace(cmd%ArrayNr%   ,&quot;^&quot; . Quote . &quot;.*&quot; . Quote . &quot;$&quot;,Quote . &quot;$0&quot; . Quote,value,1)
 IniRead,path%ArrayNr%  ,%Filename%,Buttonbar,path%ArrayNr%  ,%A_Space%
 path%ArrayNr%   := RegExReplace(path%ArrayNr%  ,&quot;^&quot; . Quote . &quot;.*&quot; . Quote . &quot;$&quot;,Quote . &quot;$0&quot; . Quote,value,1)
 IniRead,param%ArrayNr% ,%Filename%,Buttonbar,param%ArrayNr% ,%A_Space%
 param%ArrayNr%  := RegExReplace(param%ArrayNr% ,&quot;^&quot; . Quote . &quot;.*&quot; . Quote . &quot;$&quot;,Quote . &quot;$0&quot; . Quote,value,1)
 IniRead,button%ArrayNr%,%Filename%,Buttonbar,button%ArrayNr%,%A_Space%
 button%ArrayNr% := RegExReplace(button%ArrayNr%,&quot;^&quot; . Quote . &quot;.*&quot; . Quote . &quot;$&quot;,Quote . &quot;$0&quot; . Quote,value,1)
 IniRead,iconic%ArrayNr%,%Filename%,Buttonbar,iconic%ArrayNr%,%A_Space%
 iconic%ArrayNr% := RegExReplace(iconic%ArrayNr%,&quot;^&quot; . Quote . &quot;.*&quot; . Quote . &quot;$&quot;,Quote . &quot;$0&quot; . Quote,value,1)
 IniRead,menu%ArrayNr%  ,%Filename%,Buttonbar,menu%ArrayNr%  ,%A_Space%
 menu%ArrayNr%   := RegExReplace(menu%ArrayNr%  ,&quot;^&quot; . Quote . &quot;.*&quot; . Quote . &quot;$&quot;,Quote . &quot;$0&quot; . Quote,value,1)
}

; ### --------------------------------------------------------------------------
; ### write command in a file

WriteCommand(Filename,ArrayNr,FileSection,FileNr)
{
	global
	value := cmd%ArrayNr%
 IniWrite,%value%,%Filename%,%FileSection%,cmd%FileNr%
	value := path%ArrayNr%
	IniWrite,%value%,%Filename%,%FileSection%,path%FileNr%
	value := param%ArrayNr%
 IniWrite,%value%,%Filename%,%FileSection%,param%FileNr%
	value := button%ArrayNr%
 IniWrite,%value%,%Filename%,%FileSection%,button%FileNr%
	value := iconic%ArrayNr%
 IniWrite,%value%,%Filename%,%FileSection%,iconic%FileNr%
	value := menu%ArrayNr%
	IniWrite,%value%,%Filename%,%FileSection%,menu%FileNr%
}

; ### --------------------------------------------------------------------------
; ### create new command in a file

WriteNewCommand(Filename,FileSection,FileNr,v1,v2,v3,v4,v5,v6)
{
	global
	cmd0=%v1%
 path0=%v2%
 param0=%v3%
 button0=%v4%
 iconic0=%v5%
 menu0=%v6%
 WriteCommand(Filename,0,FileSection,FileNr)
}

; ### --------------------------------------------------------------------------
; ### execute em_commands

EM_Command(ByRef emCommand)
{
	Critical
	VarSetCapacity(CopyDataStruct, A_PtrSize * 3)
 VarSetCapacity(emCommandAnsi, StrPut(emCommand, &quot;cp0&quot;))
 Loop, % StrLen(emCommand)
 {
  NumPut(Asc(SubStr(emCommand, A_Index, 1)), emCommandAnsi, A_Index - 1, &quot;Char&quot;)
 }
 NumPut(Asc(&quot;E&quot;) + 256 * Asc(&quot;M&quot;), CopyDataStruct)
 NumPut(StrLen(emCommand) + 1, CopyDataStruct, A_PtrSize)
 NumPut(&amp;emCommandAnsi, CopyDataStruct, A_PtrSize * 2)
 SendMessage, 0x4A,, &amp;CopyDataStruct,, ahk_class TTOTAL_CMD
}

; ### --------------------------------------------------------------------------
; ### works together with MouseTool to detect which mouse button was pressed

GetMouseButton()
{
	MouseButton=
 Loop,5
 {
 	if(A_Index!=1){
  	Mutex := DllCall(&quot;CreateMutex&quot;,&quot;uint&quot;,&quot;0&quot;,&quot;int&quot;,&quot;1&quot;,&quot;str&quot;,&quot;BBX_&quot; . A_Index)
   LastError := DllCall(&quot;GetLastError&quot;)
 	 DllCall(&quot;CloseHandle&quot;,&quot;uint&quot;,Mutex)
 	 if(LastError!=0){
 	 	MouseButton=%A_Index%
 	 	break
 	 }
 	}
 }
 return MouseButton
}</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[HA3APET]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=28547</uri>
			</author>
			<updated>2018-03-09T09:33:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=123992#p123992</id>
		</entry>
</feed>
