The goal of this example is to demonstrate how to use a general purpose button to make a menu selection. This assumes that the reader is familiar with the basics of creating Building Blocks as demonstrated in the Detailed Tutorial.
Some applications have menus in their windows that do not have keyboard equivalents assigned to their various commands. In those cases, it can be helpful to use ControllerMate to generate a series of cursor movements and mouse button clicks to add some automation to the menu selection.
BBEdit is a text-editing application that has a menu along the lower edge of its window that is used to assign the line ending style of the current document. This example will set the line ending style of the current document to "Unix" when a button is pressed on the X-keys XK-24. The sequence of events that must occur are:
The first step is to capture a screenshot that includes the locations where the cursor will need to be moved to. In this case, the screenshot is captured while the line ending style menu is open. Next, load the screenshot image into ControllerMate's Screenshot Viewer window.
The Cursor building blocks in this example will be configured to move the cursor to a position relative to the current window's lower-left corner. That corner is identified by placing the Bottom Left Window Corner icon at the lower-left corner of the BBEdit window in the screenshot.
The next step is to setup a Cursor building block to move the cursor over the line ending style menu.
That location is identified by placing the Cursor Location icon at the the line ending style menu in the screenshot. As the Cursor Location icon is moved, the Screenshot Viewer will calculate the position relative to the Bottom Left Window Corner icon and update the Cursor building block's settings.
The Cursor building block is also configured to return the cursor to its original location when the block is turned OFF.
The next step is to add a Mouse Button building block that performs a left click. It will open the line ending style menu after the cursor has been moved.
Next, a second Cursor building block is added to move the cursor to the desired item in the line ending style menu.
A second Mouse Button building block is added to make the menu selection.
The second Cursor building block is setup to do nothing when it turns OFF. The first Cursor building block will be responsible for returning the cursor to its original location.
At this point, pressing Button #1 on the X-keys XK-24 will cause the cursor to make a menu selection in the frontmost BBEdit window.
In some cases, the cursor movements and mouse clicks may occur too quickly for the menus to respond. Adding Delay building blocks with short delays between events will give the foreground application time to respond.