 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Thu Mar 01, 2007 7:25 am Post subject: (Very?) Simple CapsLock question |
|
|
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 |
|
 |
BoBo Guest
|
Posted: Thu Mar 01, 2007 8:52 am Post subject: |
|
|
| #IfWinActive |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Thu Mar 01, 2007 9:04 am Post subject: |
|
|
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 |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Thu Mar 01, 2007 9:18 am Post subject: |
|
|
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 |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Thu Mar 01, 2007 5:55 pm Post subject: |
|
|
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 |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Thu Mar 01, 2007 6:40 pm Post subject: |
|
|
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 |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Thu Mar 01, 2007 8:02 pm Post subject: |
|
|
LOL nice! _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Fri Mar 02, 2007 1:34 am Post subject: |
|
|
| 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 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.
Thanks for the input though!
| Veovis wrote: | | btw i love you variable "omgupper" |
I'm goofy when it comes to naming variables.  |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Mar 02, 2007 2:43 am Post subject: |
|
|
| 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.
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 |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Fri Mar 02, 2007 2:47 am Post subject: |
|
|
??? _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Mar 02, 2007 2:48 am Post subject: |
|
|
Heh, fixed.  |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 362
|
Posted: Fri Mar 02, 2007 7:42 am Post subject: |
|
|
| jonny wrote: | Here:
| Code: | WinWait Untitled - Notepad
Loop {
WinWaitActive
CapsOn := GetKeyState("Capslock","T")
SetCapsLockState AlwaysOn
WinWaitNotActive
SetCapsLockState % CapsOn ? "On" : "Off"
} |
|
jonny, thanks a ton 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
Adam |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Mar 02, 2007 8:27 am Post subject: |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|