Posts: 13
Threads: 6
Joined: Oct 2012
Hi
I have prepared macro for "MS Paint".
I would like to execute this macro (hotkey) only when "Pencil" tool is selected.
If another tool is selected, the hotkey should not run the macro.
Is it possible?
How can i do this?
Anybody help me?
Posts: 12,086
Threads: 142
Joined: Dec 2002
What is your Windows version? On XP and 7 need different code.
What is better?:
1. Run if pencil button is pressed.
2. Run if mouse pointer is pencil.
Posts: 13
Threads: 6
Joined: Oct 2012
System - Windows 7 64bit.
Better is no 1 - if pencil button is pressed.
Posts: 12,086
Threads: 142
Joined: Dec 2002
The macro can look for pressed pencil button image, and don't run if not found.
Macro
Macro1870
Trigger
CSp /MSPAINT
int w=win
if(!w or !wintest(w "Paint" "MSPaintApp")) ret
if(!scan("macro:mspaint pencil pressed.bmp" child("" "NetUIHWND" w 0x1) 0 16 10)) ret
OnScreenDisplay "macro"
here "mspaint pencil pressed.bmp" is macro where I saved image captured with the 'Find image' dialog:
TFpPASYEAAACQk0mBACBADZUAAIoAAAAEs8AAQAYRAIBAADwA5gAKxMAcc7/IBIIAA4AAG3N/23N
/y9AR0BuiGK45bgBPxQAAAIAAGvL/2vL/0x8l2+VukRzmjxykaQCPBQAAAUAAGnK/2nK/2O+8FeL
tY7I/2aWyFqEorACORQAAgAAZ8j/qAAMTpfCfK/dm9H/g7ryUH+rsAI2FAACAABkx/8nCAAMS5XD
b6/agtz/ZdT1NGqMJ1wAMCAAAgAAYsb/JwgAD2HE/FmMuV+w14zr/27Y+TRqjCdoAC0gAAIAAF/F
/yoIAAtew/w7d6Jqt96R7P953HQOKnQAJywAAgAAXsT/LQgAD1y/+UKGsm+946j1/4bg9jRqjC2A
AAVexP8AAF3E/zAIAAtcwvxGjLaCzu6v+P+I4nQOLYwANdwAAANdxP9cwftRm8SH1fO9/v+ksrk8
aDUq6AACAACE0f82CAADgMv5W6fRUAYGRHQxf5WCqq6vJ6QAAgAAiNP/OQgAD4TO+WeFaI+li+rp
6pmZ1VVlt7AFAgAAjNT/PAgAAAiJ0Pq5xMiJitltbt1HS65vnt6M1P8AAJHW/z8IAAmP0vpZbsJP
XLtrkNOwBQIAAJTX/yAGCwB/susnpAAFAACW2P6Y2f8gDwgABQAAg8z3h874IA8KAAAAEQAA
However will not run when the button is hidden.
Other way would be to find accessible object, but it is slow, ~150 ms on my PC. Also, i tested, it does not work if you want to use the code in a filter function. Finding image is ~30 ms, and can make faster if need.
Posts: 13
Threads: 6
Joined: Oct 2012
sorry, i don't understand...
My Macro is "Draw-15-Macro".
In Properties - Trigger - Keyboard - Hot-key = "Win+G"
How should I set this macro to work only when the "Pencil" button is pressed?
When other tool is selected hot-key "Win+G" shouldn't work.
Step by step please
Posts: 12,086
Threads: 142
Joined: Dec 2002
That code was more like an example. May not work on your PC because of possibly different conditions. Better create your code.
Let your macro, before doing its main work, check whether pencil button is pressed. How? Add code that finds pressed pencil button image on screen, and exits macro if not found. To capture the image and create code, use this dialog: QM floating toolbar -> Windows, controls -> Find image.
In the dialog: Select 'Bitmap macro', click Capture, select button image (drag to select), OK. Uncheck all checkboxes. Then capture the control with the Drag tool. OK.
The code should look like in my example. Here it again:
int w=win
if(!w or !wintest(w "Paint" "MSPaintApp")) ret
if(!scan("macro:mspaint pencil pressed.bmp" child("" "NetUIHWND" w 0x1) 0 16 10)) ret