Posts: 17
Threads: 5
Joined: Sep 2012
This would be like a macro that for eg. performs a particular action whenever a particular window is activated everytime.
I would like to make a macro that sets the capslock state to be On or Off - depending on the current activated window.
For eg. if notepad is the current window then the capslock should get automatically be on (UPPERCASE). and if i activate any explorer window (windows explorer any folder) then capslock sets to be off. likewise if firefox is switched to, by me ie. is the current active window - capslock turns On automatically.
Can this be done in quickmacros.
thanks.
Posts: 12,087
Threads: 142
Joined: Dec 2002
Function
auto_caps_lock
Trigger
!a"Notepad" "Notepad"
int hwnd=val(_command)
ifk-(K 1) key K
wait 0 -WA hwnd
ifk(K 1) key K
Posts: 17
Threads: 5
Joined: Sep 2012
Hi,
1)
Its not obvious how do I use it and also how I customize it for other windows.
Can u explain ?
Note : I am using METAPAD text editor as a replacement of notepad (windows 7's own)
I copied the whole text in a File -> New -> function
as this -
Function auto_caps_lock
;; Trigger !a"Notepad" "Notepad"
;; Trigger !a"metapad" "metapad"
int hwnd=val(_command)
ifk-(K 1) key K
wait 0 -WA hwnd
ifk(K 1) key K
with the trigger as - !a"new file - metapad" "ahk_class metapad" (made by rightclick on the function -> properties -> trigger - window -> active
and nothing is happening when I keep capslock off and then activate the metapad.
2)
And the code is a bit complex - - how to make capslock off for a particualr window too.
Can this particular requirement guide be found in the help file ?
3)
Also can u tell me how to set similar rules for like when a window contains a particular substring in its title - like say the macro is run whenever any window title must not be the same exact as "firefox" but it may even only contain the substring "firefox". eg. - "Yahoo news - Firefox"
Posts: 12,087
Threads: 142
Joined: Dec 2002
Using code from this forum:
Tips: QM code in the forum (colors, functions, dialogs, etc)
Here is with comments.
Function
auto_caps_lock
Trigger
!a"Notepad" "Notepad"
int hwnd=val(_command) ;;get handle of the trigger window
ifk-(K 1) key K ;;if CapsLock not toggled, press CapsLock
wait 0 -WA hwnd ;;wait for the trigger-window inactive
ifk(K 1) key K ;;if CapsLock toggled, press CapsLock
By default, part of window name can be specified in trigger, eg "Notepad" will also match "Untitled - Notepad". If checked 'Use *', window name must be full or with wildcard characters. Also can be used regular expression. In Properties press F1 to read more.
Posts: 17
Threads: 5
Joined: Sep 2012
I Cant get this to work.
the code is -
Function auto_caps_lock
int hwnd=val(_command)
ifk-(K 1) key K
wait 0 -WA hwnd
ifk(K 1) key K
with trigger - !a"metapad" "ahk_class metapad"
error is coming - Error in Function3: expected 2 arguments, not 1.
NOTE - I have made this macro as by creating a new function and not a tsmenu.
Posts: 795
Threads: 136
Joined: Feb 2009
Hi,
don't want to interfere, but Gintaras's code works perfectly here, but the trigger is a bit different.
!a"metapad" "metapad"
If i don't mess, ahk_class is the class for AutoHotkey scripts windows, and it's not shown in my classname version here.
Hope this helps....
Posts: 17
Threads: 5
Joined: Sep 2012
I tried the code again -
Function auto_caps_lock
int hwnd=val(_command)
ifk-(K 1) key K
wait 0 -WA hwnd
ifk(K 1) key K
with trigger - !a"metapad" "metapad"
still when I open metapad - I get this error in QM -
Error in Function5: expected 2 arguments, not 1.
Posts: 795
Threads: 136
Joined: Feb 2009
I'm just a padawan here, sure Master Jedi will help more.....
but i'm sure you'd be better off giving all the code to help find the problem.
Seems that the problem is not in the trigger but in the implementation of function 5 which we don't know what is in code. Arguments must be splitted
so you pass two arguments, for instance.... would explain that the function waits for 2 arguments and you only send one to function..
Posts: 17
Threads: 5
Joined: Sep 2012
Gintaras, If possible, any help with the error wud be very good -
Error in Function5: expected 2 arguments, not 1
thanks.
Posts: 12,087
Threads: 142
Joined: Dec 2002
I think you don't need that line in the macro.
Posts: 17
Threads: 5
Joined: Sep 2012
Which line ?
My macro is this (A FUNCTION) -
Function auto_caps_lock
int hwnd=val(_command)
ifk-(K 1) key K
wait 0 -WA hwnd
ifk(K 1) key K
I have tried both triggers -
!a"metapad" "metapad"
and
Also this previous trigger - !a"new file - metapad" "metapad"
But both give the same error -
ERROR CODE - Error in Function5: expected 2 arguments, not 1.
I think this error would be easy to sort out as it must be a coomon error known to u.
Posts: 12,087
Threads: 142
Joined: Dec 2002
You copied too much text. Look again at my code, there are 4 lines in white rectangle.
Posts: 17
Threads: 5
Joined: Sep 2012
I see now. the error I was making was that the first line was this too in code -
Function auto_caps_lock
thanks.