1

I use AHK 1.1 to set the CapsLock to be a hotkey to toggle ArtRage full screen mode (workbench mode), I do so because ArtRage doesn't allow me to set CapsLock as a hotkey, but I'm quite used to use that key to do that in many programs, so I thought AHK could help me, my script was simple:

;   AR4 Toggle Workbench Mode
Capslock::
Send {Ctrl Down}{Right}{Ctrl Up}    ; Ctrl Right is the key I set to toogle the workbench mode
WinActivate ahk_class ArtRage 3
return
#If

The script works only the first time I enable the full screen mode and the first time I disable it, I mean the first two times I press CapsLock , but then it won't work unless I manually click on the ArtRage window. If I do so I can use the hotkey two more times. So I guess I'm somehow loosing focus on the window. I have tried also this:

Capslock::
ControlSend,, {Ctrl Down}{Right}{Ctrl Up}, ahk_class ArtRage 3
WinActivate ahk_class ArtRage 3
return
#If

with the same result, I google about it, and I tried:

Capslock::
WinGet, AR4_id, ID, A
Send {Ctrl Down}{Right}{Ctrl Up}
ControlFocus,,%AR4_id%
return

but it doesn't work at all. Hope some superuser could help me on this one.

EDITED >>>>

So Now I have tried to make the script work if WinExist AND if WinActive, is that possible? I made it like this, but it doesn't work, CapsLock still calls ArtRage on every application.

#If WinActive("ahk_class ArtRage 3")

    #If WinExist("ahk_class ArtRage 3")

    Capslock::
    ControlSend, ahk_parent, {SC037}, ahk_class ArtRage 3   ;   NumpadMult
    return

    #If

#If

EDIT2>>>>

I tweaked the code like this:

If WinActive("ahk_class ArtRage 3")

Capslock::
ControlSend, ahk_parent, {SC037}, ahk_class ArtRage 3   ;   NumpadMult
return

#If

the code works, but if ArtRage is open (not focused) and I'm in MS Word, if I press CapsLock it will not send CapsLock but it will send the "work in benchmode" in Artrage despite is not focused.

PD: Now NumpadMult is the new hotkey to enter the full screen mode (it's easier).

1
#If WinExist("ahk_class ArtRage 3")

    Capslock::
    WinActivate, ahk_class ArtRage 3
    WinWaitActive, ahk_class ArtRage 3
    Send {Ctrl Down}{Right}{Ctrl Up}    ; Ctrl Right is the key I set to toogle the workbench mode
    return

#If

EDIT:

Could it be that the program creates a new window of this ahk_class in the workbench mode? Use this to find it out:

F1::
WinGet, instances, count, ahk_class ArtRage
MsgBox, There exist %instances% windows of this ahk_class.
return

EDIT2:

Try also this as standalone script (close all other scripts that may interfere):

#If WinExist("ahk_class ArtRage 3")

    Capslock::
    ControlSend, ahk_parent, ^{Right}, ahk_class ArtRage 3
    ; or:
    ; ControlSend,, ^{Right}, ahk_class ArtRage 3
    return

#If

If it doesn't work, read https://autohotkey.com/docs/FAQ.htm#games and try the solutions mentioned there.

EDIT3:

The answer to the question how to best use the #If- or #IfWin directives depends on your situation.

The #IfWin directives are positional: 
they affect all hotkeys and hotstrings physically beneath them in the script. 
They are also mutually exclusive; that is, only the most recent one will be in effect.

https://autohotkey.com/docs/commands/_IfWinActive.htm#Basic_Operation

#if WinExist is a wide handle, but only if you give priority to it, that is, if you put it before other #if directives in the script. Try to give priority to #if WinActive directives (put them before #if WinExist in your script).

Example:

#If WinActive("ahk_class ArtRage 3")

    Capslock:: MsgBox, You pressed Capslock while ArtRage  was active

    1:: MsgBox, You pressed 1 while ArtRage  was active 

#If WinActive("ahk_class notepad")

    Capslock:: MsgBox, You pressed Capslock while Notepad was active 

    1:: Send, 2

#If WinActive("ahk_class CabinetWClass")

    Capslock:: MsgBox, You pressed Capslock while Explorer was active 

    1:: Run %A_MyDocuments%

#If WinExist("ahk_class ArtRage 3")

    Capslock:: MsgBox, You pressed Capslock while ArtRage was inactive `n(Notepad and Explorer are not active or do not exist)

    1:: MsgBox, You pressed 1 while ArtRage was inactive`nNotepad and Explorer are not active or do not exist

#If WinExist("ahk_class IEFrame")

    Capslock:: MsgBox, You pressed Capslock while IE was inactive `nArtRage does not exist,`nNotepad and Explorer are not active or do not exist

#If                 ; end of context-sensitive hotkeys


Capslock:: MsgBox, You pressed Capslock while ArtRage and IE do not exist`nNotepad and Explorer are not active or do not exist

1::  MsgBox, You pressed 1 while ArtRage and IE do not exist`nNotepad and Explorer are not active or do not exist

BTW: #If WinExist("ahk_class ArtRage 3") after #If WinActive("ahk_class ArtRage 3") doesn't make sense (The #If WinActive directive presupposes that this window exists).

  • I'm currently testing, I don't know sometimes works, sometimes not. Not working I stil have to make click on ArtRage window after performing the first two times, any idea? – litu16 Nov 29 '16 at 2:42
  • Check my edited answer. – user3419297 Nov 29 '16 at 9:32
  • Nop, it doesn't create a new instance of ArtRage, the AHK script always prints "there is only 1 window fo this ahk class. The curious thing is that I have tried that key with two macro recorders, "Key Manager" and "Hot Keyboard Pro" both work fine, so I gues there isn't nothing special on the Artrage window. can I use contrlsend in this case? – litu16 Nov 29 '16 at 11:16
  • See also EDIT2 above. – user3419297 Nov 29 '16 at 11:32
  • thanks it worked using the #If WinExist and the ahk_parent. But now the problem is that if artrage is open (even not focused) Capslock won't fire Capslock in any other application instead it will jump to ArtRage and press ^{Right}, so other apps that use Capslock to enter in full screen mode won't work, until I close either ArtRage or Autohotkey. What can I do? I EDITED my question to show what I did, Thanks Advanced. – litu16 Nov 29 '16 at 17:52
2

How about this?

*$vk14:: ; Capslock
{
    Send {vk11 Down} ; Ctrl
    Sleep 50
    Send {vk27 Down} ; Right arrow
    Sleep 50
    Send {vk11 Up} ; Ctrl
    Sleep 50
    Send {vk27 Up} ; Right arrow
}
Return

Sometimes adding key codes and adding sleep time between key presses/releases helps.

  • I'm testing.. it seems that it works, but sometimes not. Not working I stil have to make click on ArtRage window after performing the first two times, any idea? – litu16 Nov 29 '16 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.