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 

(Very?) Simple CapsLock question

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



Joined: 28 Dec 2006
Posts: 362

PostPosted: Thu Mar 01, 2007 7:25 am    Post subject: (Very?) Simple CapsLock question Reply with quote

This is just too pick your brain, there are a few ways it can be done, but what would be the best way to make CapsLock AlwaysOn for a given window when it is active, but then if that window is not active, return capslock to the state it was before that window was activated?

Thanks for the help all!

Adam


Last edited by adamrgolf on Fri Mar 02, 2007 7:49 am; edited 1 time in total
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Thu Mar 01, 2007 8:52 am    Post subject: Reply with quote

#IfWinActive
Back to top
adamrgolf



Joined: 28 Dec 2006
Posts: 362

PostPosted: Thu Mar 01, 2007 9:04 am    Post subject: Reply with quote

BoBo wrote:
#IfWinActive


Like this?

Code:
#IfWinActive,Only Capitals Here
a::A
b::b
c::C
d::D
e::E
f::F
g::G
h::H
i::I
j::J
k::K
l::L
m::M
n::N
o::O
p::P
q::Q
r::R
s::S
t::T
u::U
v::V
w::W
x::X
y::Y
z::Z
#IfWinActive


this works, accept if i turn the caps On, then all my keys are sent lowercase


Last edited by adamrgolf on Thu Mar 01, 2007 9:18 am; edited 1 time in total
Back to top
View user's profile Send private message
adamrgolf



Joined: 28 Dec 2006
Posts: 362

PostPosted: Thu Mar 01, 2007 9:18 am    Post subject: Reply with quote

This works, however, is this the easiest way to achieve this?

Code:
#IfWinActive,Only Capitals Here
a::
b::
c::
d::
e::
f::
g::
h::
i::
j::
k::
l::
m::
n::
o::
p::
q::
r::
s::
t::
u::
v::
w::
x::
y::
z::
+a::
+b::
+c::
+d::
+e::
+f::
+g::
+h::
+i::
+j::
+k::
+l::
+m::
+n::
+o::
+p::
+q::
+r::
+s::
+t::
+u::
+v::
+w::
+x::
+y::
+z::
GetKeyState,yc,CapsLock,T
if (yc="U") OR (yc="D")
   {
      StringUpper,omgupper,A_ThisHotkey
      sendinput, %omgupper%
   }
#IfWinActive
Back to top
View user's profile Send private message
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Thu Mar 01, 2007 5:55 pm    Post subject: Reply with quote

you could do a hotkey string parsing loop

Code:
;UNTESTED
#ifwinactive Only Capitals Here
keys=abcdefghijklmnopqrstuvwxyz
loop,parse,keys
{
   hotkey,%A_loopfield%,caps
   hotkey,+%A_loopfield%,caps
}
return

caps:
GetKeyState,yc,CapsLock,T
if (yc="U") OR (yc="D")
{
   StringUpper,omgupper,A_ThisHotkey
   sendinput, %omgupper%
}
return


btw i love you variable "omgupper"
_________________

"Power can be given overnight, but responsibility must be taught. Long years go into its making."
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Thu Mar 01, 2007 6:40 pm    Post subject: Reply with quote

This is simpler than it's being made out to be:
Code:
;Set title here, it will be last found for loop
WinWait Untitled - Notepad
Loop {
   WinWaitActive
   SetCapsLockState AlwaysOn
   WinWaitNotActive
   SetCapsLockState Off
}
Back to top
View user's profile Send private message
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Thu Mar 01, 2007 8:02 pm    Post subject: Reply with quote

LOL nice!
_________________

"Power can be given overnight, but responsibility must be taught. Long years go into its making."
Back to top
View user's profile Send private message Send e-mail Visit poster's website
adamrgolf



Joined: 28 Dec 2006
Posts: 362

PostPosted: Fri Mar 02, 2007 1:34 am    Post subject: Reply with quote

Veovis wrote:
you could do a hotkey string parsing loop

Code:
;UNTESTED
#ifwinactive Only Capitals Here
keys=abcdefghijklmnopqrstuvwxyz
loop,parse,keys
{
   hotkey,%A_loopfield%,caps
   hotkey,+%A_loopfield%,caps
}
return

caps:
GetKeyState,yc,CapsLock,T
if (yc="U") OR (yc="D")
{
   StringUpper,omgupper,A_ThisHotkey
   sendinput, %omgupper%
}
return


Veovis, i will try this tonight at work and let you know how it works Smile i thought i tried this because i remember reading a post of Lazlo's, but i could have done something wrong. Thanks for the help!

jonny wrote:
This is simpler than it's being made out to be:
Code:
;Set title here, it will be last found for loop
WinWait Untitled - Notepad
Loop {
   WinWaitActive
   SetCapsLockState AlwaysOn
   WinWaitNotActive
   SetCapsLockState Off
}


Johnny, this works accept that i would like caps lock to returned to the state it was in once that window is not active. So if the user had caps on outside of that window and then uses that window that caps would still be on when they go back to what they were doing. Is this possible with your code? because i'm all for having the script more compact. Smile

Thanks for the input though! Smile

Veovis wrote:
btw i love you variable "omgupper"


Cool I'm goofy when it comes to naming variables. Smile
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Fri Mar 02, 2007 2:43 am    Post subject: Reply with quote

adamrgolf wrote:
Johnny, this works accept that i would like caps lock to returned to the state it was in once that window is not active. So if the user had caps on outside of that window and then uses that window that caps would still be on when they go back to what they were doing.


Sorry. You stated it clearly in your first post, but for some reason I still set it to Off. Confused

Here:
Code:
WinWait Untitled - Notepad
Loop {
   WinWaitActive
   CapsOn := GetKeyState("Capslock","T")
   SetCapsLockState AlwaysOn
   WinWaitNotActive
   SetCapsLockState % CapsOn ? "On" : "Off"
}


Last edited by jonny on Fri Mar 02, 2007 2:48 am; edited 1 time in total
Back to top
View user's profile Send private message
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Fri Mar 02, 2007 2:47 am    Post subject: Reply with quote

Quote:
"Off"eee


???
_________________

"Power can be given overnight, but responsibility must be taught. Long years go into its making."
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Fri Mar 02, 2007 2:48 am    Post subject: Reply with quote

Heh, fixed. Razz
Back to top
View user's profile Send private message
adamrgolf



Joined: 28 Dec 2006
Posts: 362

PostPosted: Fri Mar 02, 2007 7:42 am    Post subject: Reply with quote

jonny wrote:
Here:
Code:
WinWait Untitled - Notepad
Loop {
   WinWaitActive
   CapsOn := GetKeyState("Capslock","T")
   SetCapsLockState AlwaysOn
   WinWaitNotActive
   SetCapsLockState % CapsOn ? "On" : "Off"
}


jonny, thanks a ton Smile just a few more things though since I'm all for having a simple script.

A few problems still exist with using the code you provided above, over my "excessive line" code here:

Code:
SetWorkingDir,e:\adam\ahk\aACern
Menu,Tray,Icon,aACern.ico
#Persistent
#SingleInstance,Force
SetTitleMatchMode,2
#IfWinActive,Telnet matrix.saintf.com
a::
b::
c::
d::
e::
f::
g::
h::
i::
j::
k::
l::
m::
n::
o::
p::
q::
r::
s::
t::
u::
v::
w::
x::
y::
z::
+a::
+b::
+c::
+d::
+e::
+f::
+g::
+h::
+i::
+j::
+k::
+l::
+m::
+n::
+o::
+p::
+q::
+r::
+s::
+t::
+u::
+v::
+w::
+x::
+y::
+z::
#IfWinActive,Telnet 129.1.64.11
a::
b::
c::
d::
e::
f::
g::
h::
i::
j::
k::
l::
m::
n::
o::
p::
q::
r::
s::
t::
u::
v::
w::
x::
y::
z::
+a::
+b::
+c::
+d::
+e::
+f::
+g::
+h::
+i::
+j::
+k::
+l::
+m::
+n::
+o::
+p::
+q::
+r::
+s::
+t::
+u::
+v::
+w::
+x::
+y::
+z::
#IfWinActive,129.1.64.11 - PuTTYtel
a::
b::
c::
d::
e::
f::
g::
h::
i::
j::
k::
l::
m::
n::
o::
p::
q::
r::
s::
t::
u::
v::
w::
x::
y::
z::
+a::
+b::
+c::
+d::
+e::
+f::
+g::
+h::
+i::
+j::
+k::
+l::
+m::
+n::
+o::
+p::
+q::
+r::
+s::
+t::
+u::
+v::
+w::
+x::
+y::
+z::
#IfWinActive,Reflections for UNIX
a::
b::
c::
d::
e::
f::
g::
h::
i::
j::
k::
l::
m::
n::
o::
p::
q::
r::
s::
t::
u::
v::
w::
x::
y::
z::
+a::
+b::
+c::
+d::
+e::
+f::
+g::
+h::
+i::
+j::
+k::
+l::
+m::
+n::
+o::
+p::
+q::
+r::
+s::
+t::
+u::
+v::
+w::
+x::
+y::
+z::
GetKeyState,yc,CapsLock,T
if (yc="U") OR (yc="D")
   {
      StringUpper,omgupper,A_ThisHotkey
      sendinput, %omgupper%
   }
#IfWinActive
Return


If you notice in my code it works regardless of caps lock state, so it will always be what the user has set caps as whether the windows listed in my code are active or not. Another thing I've addressed in my code is a problem I had when trying your approach (in attempt for compact code) that when capslock is set to "always on" the user could still press shift+letter and get a lowercase letter. The second problem with the code you provided is, in my code I can use settitlematchmode,2 which mainly for the window that contains "reflections for unix" because our facility uses different versions of the program that contains this title which have different titles, but all have that phrase in the title. Now, can those two things be addressed in a simpler code than what I've created/provided?

Thanks for all the great input so far Very Happy

Adam
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Fri Mar 02, 2007 8:27 am    Post subject: Reply with quote

Quote:
If you notice in my code it works regardless of caps lock state, so it will always be what the user has set caps as whether the windows listed in my code are active or not.


I'm not sure what you mean by this. Do you mean if the user presses CapsLock while one of the AlwaysOn windows are active?

Quote:
Another thing I've addressed in my code is a problem I had when trying your approach (in attempt for compact code) that when capslock is set to "always on" the user could still press shift+letter and get a lowercase letter.


I'm afraid this isn't possible without more complicated hotkeys, since this is the behavior for normal CapsLock (which is all my script sets). To eliminate all possibility to type lowercase letters, you'd have to either conditionally unmap Shift, or block all lowercase letters individually, and I'm assuming the first option isn't convenient since you'd still want shifting for other keys.

Quote:
The second problem with the code you provided is, in my code I can use settitlematchmode,2 which mainly for the window that contains "reflections for unix" because our facility uses different versions of the program that contains this title which have different titles, but all have that phrase in the title.


Yes, you can do this. Set the titlematchmode outside of the loop, and then put the window titles explicitly in the WinWaitActive and WinWaitNotActive commands (so it doesn't use the same last found window each time). For instance:
Code:
SetTitleMatchMode 2
Loop {
   WinWaitActive Notepad
   CapsOn := GetKeyState("Capslock","T")
   SetCapsLockState AlwaysOn
   WinWaitNotActive Notepad
   SetCapsLockState % CapsOn ? "On" : "Off"
}
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