WinButtons v3.2.0

2011-06-13 by Ath

Display (large) buttons on screen to send keyboard actions or start an application.

Revision history can be found in the source: WinButtons.au3

Commandline parameters

-dDebug log mode, write extra debugging and logging information to WinButtons.log Most useful if placed as first on the commandline, then also logs during command line parsing.
-d-Debug log mode disabled.
-f inifileFilemode, read configuration from inifile, instead of WinButtons.ini. -f can be ommitted.
-t <top>Top pixel of the window that shows the buttons, -1 means vertical screen-center is used.
-l <left>Left pixel of the window that shows the buttons, -1 means horizontal screen-center is used.
-w <width>Width of the buttons to display. Default is 128.
-h <height>Height of the buttons to display. Default is 128.
-m <margin>Margin between buttons and the windows border, and between each button. Default is 2.
-r <rows>Number of rows to separate the available buttons in. Default is 1.
-xRunExit mode enabled. Closes WinButtons after a button is pressed and its command executed.
-x-RunExit mode disabled (default).
-vVertical mode enabled, draw buttons from top to bottom instead of left to right.
-v-Vertical mode disabled (default).
-mvMovable mode enabled, allows dragging the form across the screen, when grabbed by its border or background, using the mouse.
-mv-Movable mode disabled (default).
-taTaskbar mode enabled, show a taskbarbutton in the Windows taskbar.
-ta-Taskbar mode disabled (default).
-bBorder enabled, show a border around the window.
-b-Border disabled (default).
-clClose button enabled, show a close button on the window, the Window Border (-b) should also be enabled!
-cl-Close button disabled (default).
-oOntop mode enabled, Button windows floats on top of all windows (default).
-o-Ontop mode disabled.
-hnd handleAdd handle to the list of window handles to hide when -hide or -hidex command switch is used, an be specified multiple times
-eEnable ExitOnEsc mode (default), to close the WinButtons window by pressing <Esc>
-e-Disable ExitOnEsc mode, pressing <Esc> won't close the WinButtons window.
-fs <size>Fontsize for use on all buttons in points (default font is fixed at 9 pt)
-aEnable ActiveExe option, to generate a list of executable names that got focus during this WinButtons session. Appended to WinButtons-active-exes.log when WinButtons is closed.
-ahEnable Alternate Hide method for another way of hiding the windows. Can also be set using althide configuration setting.
-ah-Disable Alternate Hide. (default)
-cs <separator>Set an alternate Multiple Command separator string. Default is ^, proposed alternative is &&, as ^ can not be combined with -send
-?Help mode, display a messagebox with all available commandline options.

Any commandline option overrides the corresponding setting from the inifile.

inifile settings

The [Settings] section

This is a sample [Settings] section of the inifile, all settings are shown with their default value. It applies to the current instance of WinButtons.

None of the values need to be present to have a working configuration, the defaults will then be used.

[Settings]
debug=0
caption=
runexit=0
left=-1
top=-1
buttonwidth=128
buttonheight=128
buttonmargin=2
vertical=0
border=0
closebutton=0
taskbar=0
movable=0
buttonrows=1
ontop=1
winsendkeys=
exitonesc=1
fontsize=9
backcolor=
excludeexes=
althide=
cmdseparator=
debugDebug log mode enabled when set to 1
captionThe caption of the form showing all buttons. Border must be enabled to display the caption. Environment variables can be used by using %env.variable%
runexitRunExit mode. Normally after starting a command, the form stays in place, -runx command can be used to exit this instance of WinButtons or runexit set to 1
leftLeft position of the form, -1 centers the form on the screen, after calculating the width of the form.
topTop position of the form, -1 centers the form on the screen, after calculating the height of the form.
buttonwidth / buttonheightDimension of the button(s) in pixels. All buttons will have the same size. Default is 128 x 128.
buttonmarginSpace between the buttons and the form-borders. Default is 2.
verticalDisplay a vertical column of buttons when set to 1.
borderDisplay a border around the form when set to 1.
closebuttonDisplay a standard Windows close button on the form. If taskbar = 0 a smaller close button is displayed.
taskbarDisplay WinButtons in the Windows taskbar. Allows this WinBottons instance to be selected using <Alt-Tab> or by mouse in the taskbar.
movableMakes the form movable when set to 1.
buttonrowsNumber of rows of buttons to display (assuming more than 1 button definition...). The count of buttons is divided by this number to determine the size of the form. If a number of buttons is not fully divisable by this number, void spaces are displayed instead of buttons.
ontopDetermines if the button window is foating on top of all windows, or can be hidden behind other windows. Default set to 1, disabled when set to 0.
winsendkeysSpecify the path/filename for WinSendKeys.exe (download from http://www.donationcoder.com/forum/index.php?topic=25389.0). Not checked for existence, just executed (can be in path).Will be read from WinButtons.ini, if not found in the current .ini file (and current file is not WinButtons.ini)
exitonescWhen set to zero won't close the WinButtons windows when <Esc> is pressed. Is read from global ini, so sub-menus should probably provide a button to quit that menu.
fontsizeThe global fontsize to be used for all buttons. Can be overridden by specific button fontsize<n> setting.
colorThe default color of the button-face, can be overridden by a group or button setting
textcolorThe default color of the text on the buttons, can be overridden by a group or button setting
backcolorThe background color of the WinButtons window. Color values in rgb, most easy is to use hexadecimal notation with 0x prefix, like 0xff0000 for red.
excludeexesThe comma-separated list of exe files, not to trigger a change of button context when [Groups] are defined.
althideUse Alternate Hide method (WinSetState instead of SetWindowPos) for hiding a Window, in case of re-painting issues.
cmdseparatorSet the character(s) to be used as Multiple Command separator. Default is ^, proposed alternate could be &&, as ^ can not be combined with -send

If a setting is not found for: debug, buttonwidth, buttonheight, buttonmargin, closebutton, border, taskbar, ontop, exitonesc, winsendkeys, fontsize, excludeexes, althide or cmdseparator in the current ini file, and we are not reading WinButtons.ini, then the setting is also searched in WinButtons.ini as a global configuration. Local override or command-line option always 'wins'.

The [Groups] section of the configuration.

Groups can be defined to switch the set of available buttons, based on the current application having focus. The selection is made based on the name of the exe file (no path) that is running.

This information can be obtained by enabling debug mode or -a commandline parameter, starting WinButtons, giving the required application focus, closing WinButtons and reading the last lines of the log file.

There's a list of the executable names that had focus during the lifetime of that WinButtons session.

Groups have 2 parameters:

group1=scite
exename1=scite.exe
group<n>The name of the group, to be used to identify the button-section. This name will be prefixed to '-Buttons' to find the correct set of buttons. So for this group to activate, a non-empty section [scite-Buttons] must be defined, listing a set of buttons as defined in the [Buttons] section readme.
exename<n>A comma-separated list of names of executables that should have focus to validate the context-switch to this button-group. The check is done non-case-sensitive. Application-exename(s) can be determined by starting WinButtons with -a commandline option, activvating the required app, closing WinButtons and retrieving the activated exename(s) from WinButtons-active-exes.log. It is also possible to trigger a group-switch by specific controls on a specific window of that exe, the format for the exename is: exename.exe[%["special window title"%]ControlName]. The (optional) window title can be specified like the special names in http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm in the section Advanced Window Descriptions. The ControlName can be specified as a regular expression, and should name the ClassnameNN value, as shown by the AutoIt Window Info tool. Usually these names as like Edit1, Edit2 etc. The regex would be Edit[1-3] for Edit1, Edit2 and Edit3. These names may not appear of be detectable in all Windows applications though. The regular expression syntax for these is explained in this page: http://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm and the full supported syntax over here: http://www.autoitscript.com/autoit3/pcrepattern.html

If a group is used, some parameters from [Settings] can be overridden by setting them in that [<group>-buttons] section.

These overridable settings are: left, top, buttonwidth, buttonheight, buttonmargin, buttonrows, vertical, fontsize, color, textcolor and backcolor.

The [Variables] section of the configuration.

Variables can be defined in a [Variables] section, to be later used by other [Variables], [Settings] or [Buttons]/[<group>-Buttons] parameters or commands.

A variable could be defined like:

[Variables]
Hello=Hello World!
stdheight=60
stdwidth=2*:varStdHeight:

This variable can then be used in a command or caption, etc., by using a ":var" prefix and a ":" suffix, for example: :varhello: or :varStdWidth:

The :var prefix is required to be lowercase, variablenames are not case-sensitive.

The variables can be used in all configuration items that do _not_ resolve to an on/off value, like vertical or movable. Only numeric and string values get variables replaced.

An example configuration is included as copymenu.ini

Nested variables can be used, the replacement happens from inside out, like this example:

[Variables]
stdheight=100
stdwidth=:varMultiply:varStdHeight:::varStdHeight:
multiply40=4*
multiply60=3*
multiply100=2*

The use of :varStdWidth: resolves to: ":varMultiply:varStdHeight:::varStdHeight:"

The second iteration resolves to: ":varMultiply100:100"

The third iteration resolves to: "2*100"

Assigning this variable to buttonwidth in the [Settings] section, like below, will resolve to 200, as any calculation is also executed when reading numeric values from the configuration.

Example:

[Settings]
buttonwidth=:varStdWidth:

Changing the value of stdheight to 60 will resolve in a buttonwidth of 180, and a stdheight of 40 results in buttonwidth=160.

Variables can also process parameters. An example:

[Variables]
root=F:\Projecten\AutoIt\WinButtons\copytest
rootx=.
source1=:varRoot?1:\client\import
dest1=:varRoot?1:\server\import
filespec1=*.*
source2=:varRoot:\server\import
dest2=:varRoot:\client\import
filespec2=
source3=:varRoot:\client\export
dest3=:varRoot:\server\export
filespec3=
source4=:varRoot:\server\export
dest4=:varRoot:\client\export
filespec4=
command=:varCmd: :varSource?1=?2: :varDest?1=?2: :varFileSpec?1: :varParams:
params=/E /MOV ?1
cmd=robocopy

; (Part of the Variables with parameters demo)
[Buttons]
button1=Copy IMPORT from &Client to Server  i >>
command1=-asc"Please confirm|:varCommand=1=x:":varCommand=1=x:

Parameter values are passed by using =<value> in the variable: :varCommand=1=x: passes values "1" and "x" when parsing variable Command. These parameters can be applied in the result by using ?<parameter number>, like: ?1 or ?2.

These passed values can again be used as parameter value by preceding them with "=", like: :varSource?1=?2: This results in variable Source1 being fetched (the first parameter to that variable), and passing x to Source1 (the second parameter passed from the command1 button).

In Source1 this value "x" is used to determine the requested Root variable, either Root or Rootx. If parameter 2 is not passed to Command, it defaults to an empty string.

The [Buttons] section of the configuration.

Each button is required to have at least a, sequentially numbered, non-empty button<n>= value. If the text on a button should be empty, an empty caption<n>= value should be supplied.

[Buttons]
button1=
caption1=
tooltip1=
image1=
command1=
color1=
textcolor1=
buttonwidth1=
buttonheight1=
buttonarrangement1=
fontsize1=
condition1=
conditionmode1=
dropcommand1=
button<n>The name of the button. If no caption<n> is supplied, this is also the text displayed on the button. & can be used to define a hotkey for that button, so button1=B&utton defines <Alt-U> as a hotkey for button 1.
caption<n>The caption to display on the button. If supplied it takes precedence over the standard button<n> value for display on the button. Allows an empty caption if defined as empty value. The same rules for hotkeys apply. Captions are wrapped if no color is used, as these attributes don't play nice together (yet). Environment variables can be used in a buttonid or a caption by using %env.variable%. The caption is also shown as a tooltip for each button, if no tooltip is defined.
tooltip<n>The tooltip to display for this button. Overrides the default 'caption' tooltip. AutoIt3 macros and variables can be used by enclosing them in @ or $, like @CRLF@ to insert a new-line. Full macro documentation in http://www.autoitscript.com/autoit3/docs/macros.htm
image<n>An optional icon (ico) or bitmap (bmp) file to display on the button. Doesn't allow for combination of icon/bitmap and text! If a hotkey is set using an & in the button or caption setting, then that hotkey is still enabled!
command<n>
The commandline to execute on activation of the button. It has a few optional switches that need to be left-most if used (all lower-case):
-quitQuit this instance of WinButtons. Ignores the rest of the command.
-exitExit after executing command, like runexit configuration parameter was set or -x commandline option used
-waitRun command, wait until it's finished, and re-activate the WinButtons window.
-hideHide this WinButtons instance and any window-handles passed using -hnd option, run the command, wait for it to finish and restore WinButtons. This allows an uncluttered screen, as default WinButtons has 'always on top' parameter (ontop) set. If you need to hide the menus only when the last level is shown, then either don't pass :hndlist:, or only use -hide on the last level, or else all previously hidden windows will reappear.
-sendSend keys specified to a named window using WinSendKeys (see winsendkeys [Settings] parameter for download including docs). Use -wait to wait for completion of WinSendKeys (not the app controlled by WinSendKeys!)
-subStart another instance of WinButtons with the parameters given. -wait is also turned on
-nowaitTurn off -wait option (for optional use with -sub)
-work "workdir"
Specify a working directory for the command to execute. The path need not be quoted, unless it contains spaces. If it's not quoted, it's terminated with the first space encountered after some valid (non-space) characters. The workdir path isn't explicitly checked for existence, but Windows won't start the command if it can't find that directory.
Example: (all with the same result)
  command5=-hide-work "c:\tmp "Notepad
  command5=-hide-workc:\tmp Notepad
  command5=-hide-work"c:\tmp"Notepad
This hides WinButtons while running Notepad, which is started in C:\tmp. The extra space inside the quotes in the first example is ignored by Windows.
-msgDisplay the rest of the command as a message to the user. This can be used during debugging to display the command, instead of actually executing it. Supports optionally setting a title by having a | as separator. -hide is implicitly set.
-ask"[title|][*]message"Ask with a Yes/No messagebox, displaying the message, with optional title separated by | (vertical bar), confirmation of the user. On No the command won't be executed. -hide is implicitly set.
-asc"[title|][*]message"Ask with a OK/Cancel messagebox, displaying the message, with optional title separated by | (vertical bar), confirmation of the user. On Cancel the command won't be executed. -hide is implicitly set. If the message part starts with * then the second button (Cancel or No) is set as the default button, and the * is removed. When the button is pressed, any variables in the message or title are replaced.
-reloadCauses a reload of the configuration after the button is executed, assuming no -exit or runexit=1 or -x is set.
-refreshCauses the WinButtons windows to be redrawn, without reloading the configuration, after the button is executed, assuming no -exit or runexit=1 or -x is set.
-recondCauses all conditions to be re-evaluated ('recondition'). Is only useful with conditionmode > 0 (or combined with -dis or -vis condition options).
-miniStarts the command in a minimized state. Can be used to avoid 'flashing' cmd prompts for commandline-tools that generate (ignorable) screen-output when executed.
Switches can be combined, placed side by side, or separated by a space, so a valid command<n> like could look like:

  command1=-hide-exitNotepad somefile.txt

This hides WinButtons, and any windows passed using -hnd option, while working with Notepad, and quits after Notepad has returned to WinButtons.

or

  command1=-wait-exit Notepad somefile.txt

This doesn't hide WinButtons, waits for Notepad to end, and then quits WinButtons

or

  command1=Notepad somefile.txt

This runs Notepad, and makes WinButtons directly available again for further actions.
Environment variables can be used by using %env.variable%, like:

  command1=-hide-exitNotepad %USERPROFILE%\Desktop\notes.txt
When passing parameters to a command, it can be useful to pass information about the current location of the WinButtons window, or button just selected. Some coordinates are avaliable with these parameters:
:top:top pixel of the control, ignores bordersizes so buttons can align nicely. If a sub-instance of WinButtons is started that has the same border settings, then the buttons can align exactly
:left:left pixel of the control, ignores bordersizes so buttons can align nicely.
:right:right pixel of the control
:bottom:top: + buttonheight
:btop:button top exactly calculated.
:bleft:button left exactly calculated.
:bright:utton right exactly calculated.
:wtop:window top
:wleft:window left
:wwidth:indow width
:wheight:indow height
:wright:indow right (:wleft:+:wwidth:)
:wbottom:indow bottom (:wtop:+:wheight:)
:width:button width
:height:utton height
:hndlist: list of all handles passed using -hnd option, and the handle of the current window, to be hidden when -hide is used
:var<VarName>[=par[...]]:ariables with optional parameters, as explained in the [Variables] configuration section, can be used.
These coordinates can be used in calculations to give nice positioning (if spaces are used for readability, then the calculation should be quoted, examples from the standard WinButtons.ini) like:

  command7=-sub -t :btop:+(:height:*0.75) -l ":bleft: + (:width: * .25)" :hndlist: submenu5.ini

This places a submenu (configured using submenu5.ini) at 3/4 down the height of the selected button, and 1/4 to the right, overlapping a large part of the button, but leaving the caption visible. It also passes the list of handles to hide if -hide is used.

  command8=-sub -x -t :top: -l :right: submenu4.ini

This places a submenu on top of the selected button, overlapping it exactly, assuming both use the same border, taskbar and buttonsize settings
Multiple commands

If multiple commands need to be sent by 1 buttonpress, then they should be separated by a ^ or an alternative set with -cs commandline option or cmdseparator setting, so if we need to create 2 directories, this can be configured like this:

  command1=-wait cmd /c md c:\directory1^cmd /c md c:\directory2

The second command can run in parallel with the first if no -wait is used!

Only the last return value is 'preserved' (logged if -d or debug was set).

Multiple commands can only properly be combined with -send if an alternate for ^ as a command separator is set using cmdseparator setting or -cs commandline option.
dropcommand<n>
The command to execute when files are dropped on this button. The same variables and options like command<n> are available. Adds these variables : (only feasible when some files are dropped)
:dropList:List of all files dropped on the button (space-separated, and quoted when containing spaces)
:dropItem<n>:The n-th item in the list dropped (1-based). If :dropItem: or a non-numeric <n> is used then :dropItem1: is assumed. If <n> is out of range of dropped items this variable returns empty. (quoted when containing spaces)
color<n>Change the button surface color. Color values in rgb, most easy is to use hexadecimal notation with 0x prefix, like 0xff0000 for red.
textcolor<n>Change the caption color of the button, same notation as color<n> parameter. Colors can't currently be combined with a button image.
buttonheight<n>Change the height of this button only. If it's taller then the global buttonheight setting, then only this button will be taller, but all other buttons get a bigger margin.
buttonwidth<n>Change the width of this button only. If it's wider then the global buttonwidth setting, then only this button will be wider, but all other buttons get a bigger margin. If these values differ from the global buttonheight/buttonwidth values, then this button will be differently sized, and smaller button(s) will be centered in the available space. If a larger margin between buttons and/or the border is needed, then [Settings] value for buttonmargin should be increased, instead of giving all buttons a different size.
buttonarrangement<n>
Determine how the button is grouped/sized within a buttonarea. Possible values: 1, 2, -2, 3, -3, 4, 6, -6, 9
1The current button is extended into the next buttonarea, it's possible to have the rest of the buttons fall off the window...
2The buttonarea is split horizontally in 2, so 2 buttons can be placed into 1 buttonarea, can be combined with 3, 4, 6 and 9, vertical on with -3, 4, -6 and 9
-2he buttonarea is split vertically in 2, so 2 buttons can be placed into 1 buttonarea, can be combined with -3, 4, -6 and 9, vertical on with 3, 4, 6 and 9
3The buttonarea is split horizontally in 3, so 3 buttons can be placed into 1 buttonarea, can be combined with 2, 4, 6 and 9, vertical on with -2, 4, -6 and 9
-3he buttonarea is split vertically in 3, so 3 buttons can be placed into 1 buttonarea, can be combined with -2, 4, -6 and 9, vertical on with 2, 4, 6 and 9
4The buttonarea is divided into 4 equal parts, so 4 buttons can be placed into 1 buttonarea, can be combined with 2, 3, 6 and 9, vertical on with -2, -3, -6 and 9
6The buttonarea is divided into 6 parts, 2 horizontal rows, vertically divided into 3 equal parts, and 6 buttons can be placed into 1 buttonarea, can be combined with 2, 3, 4 and 9, vertical on with -2, -3, 4 and 9
-6he buttonarea is divided into 6 parts, 2 vertical rows, horizontally divided into 3 equal parts, and 6 buttons can be placed into 1 buttonarea, can be combined with -2, -3, 4 and 9, vertical on with 2, 3, 4 and 9
9The buttonarea is divided into 9 equal parts, so 9 buttons can be placed into 1 buttonarea, can be combined with 2, -2, 3, -3, 4, 6 and -6, also with vertical on
Several combinations of buttons can be made, so 3x 9, 1x 3 and 3x 9 will fill 1 buttonarea, but 3x 6 and 1x 2 also fill a buttonarea. Experimenting is the best way to find the best way to see if it fits your need.

When buttonwidth and/or buttonheight are different from the calculated buttonsize, then the smaller of these sizes will be used.

These smaller buttons are combined/calculated using the default calculated sizes, not the actual sizes, that's for another release, if required.

The buttonarrangement type 4 and 9 buttons are drawn from left to right, top to bottom when vertical is off, and from top to bottom, left to right when vertical is on.
fontsize<n>The size of the font in points, used for this button only. By default the [Settings] value of fontsize will be used, which defaults to 9pt.
condition<n>
A condition that has to return true for the button to be displayed. Valid condition options are:
-visSet ConditionMode for this button to 1, show/hide the button on condition change. See conditionmode<n> 1 below for more info.
-disSet ConditionMode for this button to 2, enable/disable the button on condition change. See conditionmode<n> 2 below for more info.
-refRefresh condition evaluation every 1/10th second. Having too many -ref conditions can cause performance/responsiveness issues!
-file"dir or filespec"Check for existence of a directory or file specification. Quotes are advised to be used, to accomodate for spaces in names, else the first space is used as a separator.
-exe"executable name"Check for "executable name" (no path should be specified), or a comma-separated list of executables (checked using 'OR' logical condition), to be active in memory. If 'AND' logical condition is required, then use multiple -exe combined with -and options. This check is performed at startup, but also when a new process is started, or some process has closed. -ref is not needed for this condition to be re-checked.
-au3"AutoIt3 functionblock"Provide a valid AutoIt function block that results in a logical or numeric (0 : False, <> 0 : True) value. Use @macro@ notation to check specific macro values, documentation: http://www.autoitscript.com/autoit3/docs/macros.htm. Use -ref to refresh this condition if a dynamic macro value, like @SEC@ or @HOUR@ is used.
-not, -and, -orConditional keywords to invert (-not) or tie conditions together. Be sure to add a condition after these options to get a valid logical result!
(, )Use round brackets to group conditions together. Be sure to match the correct number of round brackets to get a valid logical result!
In the condition statement, all :var<VariableName>: variables, macro expansion using @macro@ and environment variables using %env.variable% are supported.

When -exe is used, every time a process is started or stopped, the list of conditions that contains a -exe is re-evaluated.

When -ref is used, every 1/10th second, the list of conditions that contains a -ref is re-evaluated. This might drain performance! A 'flashing' button can be realized by using:

  ...
  condition1=-dis-ref-au3"mod(@SEC@,2) = 0"
  ...

Examples are in copymenu.ini

An invalid, but non-empty, condition always evaluates to False, so the button won't be displayed or will be disabled!
conditionmode<n>
1The condition shows/hides the button. If the condition is false an empty spot is displayed. Can also be set by condition option -vis.
2The condition enables/disables the button. If the condition is false a greyed-out button is displayed. Can also be set by condition option -dis.
0The entire WinButtons windows is re-drawn (giving screen-flicker) if a button-condition changes state. (default)