AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AUTOCAPS for work program

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
crxvfr



Joined: 10 Mar 2006
Posts: 55

PostPosted: Tue Apr 29, 2008 8:48 pm    Post subject: AUTOCAPS for work program Reply with quote

We have to use caps at work in one app only. I'm trying to make something that will turn the caps lock on automatically if one of the windows for this app has focus. This works great on my computer, but on some, something causes the caps to keep going on and off very quickly. From looking at the cap lock light you can tell it is looping on/off - on/off.
I'm not an ace. Improvements with any part of what I am doing will be greatly thank you'd in advance.

Code:

#SingleInstance force
#NoEnv
Process Priority,,High
SetBatchLines 100

CheckWinTitle:
Loop
   {
      turncapson="Window Title 1", "Window Title 2", "Window Title 3"
      WinGetActiveTitle, active_title
      IF turncapson contains %active_title%
         SetCapslockState, On
      else
         GetKeyState, CapsVar, Capslock, T
            if CapsVar = D
               SetCapslockState, Off
   
   }
return
Back to top
View user's profile Send private message
SomeGuy



Joined: 21 Apr 2008
Posts: 96
Location: somewhere

PostPosted: Tue Apr 29, 2008 8:58 pm    Post subject: Reply with quote

Code:
turncapson=Window Title 1,Window Title 2,Window Title 3
WinGetActiveTitle, active_title, A
IF active_title in %turncapson%
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Tue Apr 29, 2008 9:05 pm    Post subject: Reply with quote

I would do it a different way

Code:

#SingleInstance force
#NoEnv
;Process Priority,,High
SetBatchLines -1
SetTitleMatchMode, Regex    ;2 works as well

CapsOnWindowList =
(
Window Title 1
Window Title 2
Window Title 3
)
UserWantsCapsLock := false

SetTimer, CheckWinTitle, 50
Return

CheckWinTitle:
ProgramWantsCapsLock := false
Loop, parse, CapsOnWindowList, `n, `r
   {
    If WinActive(A_LoopField)
      ProgramWantsCapsLock := true
    If (ProgramWantsCapsLock or UserWantsCapsLock)
      SetCapslockState, On
    else
      SetCapslockState, Off
   }
Return

CapsLock::
UserWantsCapsLock := !UserWantsCapsLock
Return


Since you were checking multiple programs, it was flickering on and off quickly (not all three programs were active at the same time) If you have it in just one program, it would work fine.

TESTED

SomeGuy's fix also works. " around titles is optional in your list.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
crxvfr



Joined: 10 Mar 2006
Posts: 55

PostPosted: Wed Apr 30, 2008 8:08 pm    Post subject: Reply with quote

Many thanks guys.

I messed around with it using both versions, learning/figuring as I go.

The later version allows the user to use the caps lock key normally in other windows!

You help helped to put an end to the griping and resistance to implement from a couple dozen people. Hehe thanks

I've seen may work places that use programs that operate with cap locks. I'm sure I won't be the only one that uses the bit of code you posted.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Wed Apr 30, 2008 9:14 pm    Post subject: Reply with quote

Yes, the goal was to let capslock be used normally elsewhere. I should have mentioned that before.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Wed Jul 30, 2008 1:41 am    Post subject: Reply with quote

preston via PM wrote:
You have helped me before, and I ask, humbly, yet again...

The setcapslock script you wrote in the post, works perfectly.
However, while using it, I encounter problems with auto-replace.

Example....

::CL::CAPSLOCK

Ends up looking like this:

CApslock

or:

CAPSLOck

It's not consistent, so I'm confused.
I already had similiar code
Code:
#persistent
detecthiddenwindows, on
settimer, CAP, 250
CAP:
settitlematchmode, 2
ifwinactive, Solid
{
setcapslockstate, on
return
}
else
{
setcapslockstate, off
return
}

insert::
pause
return

#NoTrayIcon

I was just looking to improve functionality.
While "my version" was more reliable, I still received the aforementioned errors.

How could I use your code, and not encounter those problems?
Thank you in advance for your time.....

P.S. I would just retype the letters, but the program I'm using this
with does not recognize the case change upon retype.


Code:


#SingleInstance force
#NoEnv
;Process Priority,,High
SetBatchLines -1
SetTitleMatchMode, Regex    ;2 works as well

CapsOnWindowList =
(
Window Title 1
Window Title 2
Window Title 3
)
UserWantsCapsLock := GetKeyState("Capslock", "T")

SetTimer, CheckWinTitle, 50
Return

CheckWinTitle:
ProgramWantsCapsLock := false
Loop, parse, CapsOnWindowList, `n, `r
   {
    If WinActive(A_LoopField)
      ProgramWantsCapsLock := true
    If (ProgramWantsCapsLock or UserWantsCapsLock) and !GetKeyState("Capslock", "T")
      SetCapslockState, On
    else If !(ProgramWantsCapsLock or UserWantsCapsLock) and GetKeyState("Capslock", "T")
      SetCapslockState, Off
   }
Return

CapsLock::
UserWantsCapsLock := !UserWantsCapsLock
Return


I haven't tested this one, but give it a shot. It basically is the same as before, but doesn't try to turn on Capslock if it is already on. This might make your letters stay the right case.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
preston



Joined: 12 Mar 2008
Posts: 44

PostPosted: Wed Jul 30, 2008 11:55 am    Post subject: Reply with quote

Enguneer,
No difference.
Is there maybe a different way to tackle it?
I don't know. I'm running out of ideas.
The auto-replace works fine, if I'm not running the capslock script.
Why is that?
Should I put the auto-replace hotstrings into the capslock script?
I would rather not, because they are only for one program, and I don't want them popping up anywhere else.
It seems to me that combining the two scripts and "enguneering" them
to cooperate would be the way to go.
For instance, having the capslock check pause if the hotstrings are
activated?
It must have something to do with that timer....
Anyhow, I appreciate your help....
You're an autohotkey pimp. Laughing
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Thu Jul 31, 2008 3:37 am    Post subject: Reply with quote

try increasing the SetTimer line to use a higher number (try 1000 to be extreme) and see if it still interferes, or at least interferes less, then maybe the timer is causing it. I also could have a bug relating to my latest modification. Try this variation and see if the tooltip is always increasing, or just once every time you change capslock state by changing windows

Code:



#SingleInstance force
#NoEnv
;Process Priority,,High
SetBatchLines -1
SetTitleMatchMode, Regex    ;2 works as well

CapsOnWindowList =
(
Window Title 1
Window Title 2
Window Title 3
)
counter = 0
UserWantsCapsLock := GetKeyState("Capslock", "T")

SetTimer, CheckWinTitle, 50
Return

CheckWinTitle:
ProgramWantsCapsLock := false
Loop, parse, CapsOnWindowList, `n, `r
   {
    If WinActive(A_LoopField)
      ProgramWantsCapsLock := true
    If (ProgramWantsCapsLock or UserWantsCapsLock) and !GetKeyState("Capslock", "T")
      {
       SetCapslockState, On
        counter++
      }
    else If !(ProgramWantsCapsLock or UserWantsCapsLock) and GetKeyState("Capslock", "T")
      {
        SetCapslockState, Off
        counter++
      }
   }
tooltip, counter is %counter%
Return

CapsLock::
UserWantsCapsLock := !UserWantsCapsLock
Return


If it only counts when you change windows, then I am unsure of the problem. If it counts constantly, then I had a bug.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
preston



Joined: 12 Mar 2008
Posts: 44

PostPosted: Thu Jul 31, 2008 11:36 am    Post subject: Reply with quote

Enguneer,
The tooltip counts only once per window change.
I made the modification to the timer.
That seems to have corrected the problem.
Why is that?
Can you shed some light on that?
In the meantime, I will play with it to see how low I can get the timer.
Enguneer, thank you for your help.
Guys like you are what makes this forum possible.
Thank you.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Fri Aug 01, 2008 3:20 am    Post subject: Reply with quote

probably something to do with checking the state of the capslock key or setting the capslock key (even if it is in the same state) interfereing with the hotstring actually typing things out.

are you using AHK v1.0.43 or later? If not, you should upgrade and see if it fixes the issue, since the hotstring will now be using SendInput mode by default, where it uses SendPlay mode in older versions.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
preston



Joined: 12 Mar 2008
Posts: 44

PostPosted: Fri Aug 01, 2008 1:25 pm    Post subject: Reply with quote

Version 1.0.47.04

I don't know what else could be causing it.
I have it working about 85% of the time now.
One wierd thing though....
There is a certain "childwindow" that pops up.
I assume that's similiar a print window, or something...(sorry noob here).
It matches the criteria I have set the script to look for.
But the script flashes the Capslock light on and off.
If I hold down a letter, every 10th letter or so will be a cap.
Curious........
It's like the script see's the criteria, and gets hung checking that window
over and over again.....Wierd....
Enguneer, I don't want to take up anymore of your time.
I DO appreciate your help, very much, but I'm sure you've got better things to ponder on. I'll post back here if I make any progress.
Thanks again,
Preston
Back to top
View user's profile Send private message
preston



Joined: 12 Mar 2008
Posts: 44

PostPosted: Tue Aug 05, 2008 1:08 pm    Post subject: Reply with quote

UPDATE:
Using the last posted code has posed the problem of the CAPSLOCK light
flickering on and off with varying speed. I've found that once I edit the script, and choose to run it again, instead of reload, is when the light begins to flicker.
This must be associated with the #SingleInstance, Force...
I've read everything I can find, but I'm not quite sure what the specific problem is.
The way I run the script, after editing, must leave the old instances
still running, and therefore they must be fighting against each other.
I've removed the tray icon. Which means, I have to kill the older instances through task manager.
Is there a better around this?
Back to top
View user's profile Send private message
preston



Joined: 12 Mar 2008
Posts: 44

PostPosted: Mon Oct 27, 2008 3:13 pm    Post subject: Reply with quote

ENGUNEER,
I have stumbled upon a fix for the "cAPSloCk" issue, I was having.
The one that makes EVeryThinG lOOk LIkE tHIs.........

#hotstring SI

I didn't know SendInput was used by default, and therefore used the above command, and bingo!

Version 1.0.47.04
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group