How can I determine the state of a checkbox or radio button?
Macro Express does not have a macro command that allows you to determine the state of a checkbox or radio button, but there are ways to do this using existing macro commands.
This technique will work to determine the state of a checkbox or a radio button. To simplify, this description will only refer to a checkbox.
Several steps may be needed. First, get the position of the checkbox, second, use the Get Pixel Color command to determine whether the checkbox is checked and third, use an If Variable command to take specific action if the checkbox is checked or unchecked.
There are several ways to determine the position of the checkbox:
- If the checkbox is in a fixed position on a dialog window, you can use the Mouse Locator when writing your macro to get the position of the checkbox and use those coordinates directly in your macro.
- If the checkbox is not in a fixed position but it is a Windows Control, you can use the Window Control commands to get the position. Use the Get Control command to set a control variable and then use the ‘Variable Set Integer from Control Left’ and ‘Variable Set Integer from Control Top’ to get the screen position coordinates. (There is a tutorial in the Macro Express help that describes how to use the Window Control commands.)
- If the checkbox is not in a fixed position and it is not a Windows Control, you probably will need to move the mouse to the checkbox and then use the Get Mouse Position command. To move the mouse to the checkbox, you may need to send keystrokes. For example, you might be able to use an Alt shortcut or you may need to send a series of s.
- If the checkbox is in a fixed position on a dialog window, you can use the Mouse Locator when writing your macro to get the position of the checkbox and use those coordinates directly in your macro.
Once you know the position of the checkbox, use the Get Pixel Color command to determine if the checkbox is checked. The Get Pixel Color command will set an integer variable (%N1%, for example) to the value of the pixel on the screen. Black has a pixel color value of 0.
You may need to adjust the position coordinates to make sure you are looking at a part of the checkbox that turns black when checked.
Then, using the ‘If Variable’ command, you can have your macro take a specific action such as clicking on the checkbox to uncheck it.
Sample Macro Express 3 macro:
Get Control %C1%
Variable Set Integer %N2% from Control %C1% Left
Variable Set Integer %N3% from Control %C1% Top
Variable Modify Integer: %N2% = %N2% + 4
Variable Modify Integer: %N3% = %N3% + 6
Get Pixel: Screen Coords: %N2%,%N3% into %N1%
If Variable %N1% = 0
// The box is checked
Else
// The box is unchecked
End If
Sample Macro Express Pro macro:
Get Control: (MACEDIT.EXE) Using z-order -> %C[1]%
Variable Set Integer %N[2]%: Set to a Control’s Left (%C[1]%)
Variable Set Integer %N[3]%: Set to a Control’s Top (%C[1]%)
Variable Modify Integer: %N[2]% = %N[2]% + 4
Variable Modify Integer: %N[3]% = %N[3]% + 6
Get Pixel Color at (%N[2]%, %N[3]%) Relative to Screen into %N[1]%
If Variable %N[1]% Equals “0”
// The box is checked
Else
// The box is unchecked
End If
– Applies to: Macro Express and Macro Express Pro