How to switch on or switch off CapsLock

Articles, advices, FAQ, etc.
Post Reply
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

How to switch on or switch off CapsLock

Post by Oleg »

How to switch on or switch off CapsLock, NumLock and ScrolLock

When third-party applications are automated the emulation of key pressing is often used to fill in the entry fields with necessary values. Meanwhile, sometimes it is important that the keys CapsLock, NumLock and ScrollLock should be in a definite status: On or Off. Otherwise, the entry fields of a dialog can be filled in with incorrect values.
Now we will look at the ways to put these keys in a definite status.

To identify the status of Lock keys there are system variables in RoboTask:
  • {CapsLockState}
  • {NumLockState}
  • {ScrollLockState}
These variables return a logical value “True” or “False” which corresponds to the status of a key. “True” means ON, “False” means OFF.
You can find these variables in the group of variables "Keyboard".
Image
Image


For example, to switch off CapsLock, the algorithm suggests itself:
  • Examine the status of a key.
  • If it is on, press CapsLock.
We do the same manually: look at the Scroll-Lock LED and press the key if the lamp is on.

Look how it works in the prepared example.

Save the text of the task in a file and use the menu Task -> Import to import the task in the RoboTask.
leopoldus
Posts: 20
Joined: Fri Oct 22, 2010 11:22 pm

Re: How to switch on or switch off CapsLock

Post by leopoldus »

For example, to switch off CapsLock, the algorithm suggests itself:
Examine the status of a key.
If it is on, press CapsLock.
The idea itself is simple and clear, but very useful. However could you please provide a bit more detailed instructions for this example. I mean, step by step explanations what and where to write or paste in order to compose the proper task to switch CapsLock automatically off if it is switched on by some app or user.

I've just started to learn the app, so some simple things are very complex fore me :oops:
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How to switch on or switch off CapsLock

Post by Oleg »

The prepared task is here: http://www.robotask.com/tasks/Turn%20off%20Capslock.tsk
(the link is in initial post)
The task is very simple and contains only three steps.

Save the task into a file and use menu Task->Import to import into RoboTask
Oleg Yershov
leopoldus
Posts: 20
Joined: Fri Oct 22, 2010 11:22 pm

Re: How to switch on or switch off CapsLock

Post by leopoldus »

Oleg wrote:The prepared task is here: http://www.robotask.com/samples/Turn%20 ... pslock.tsk
The task is very simple and contains only three steps.
Save the task into a file and use menu Task->Import to import into RoboTask
Thank you. I've imported the task according your instructions, but it does not do anything.
I've even tried to start the task different ways, the results of the test is following:

1. Automatically - does not start, when I switch CapsLock on (even if the current window is Robotask main window).

2. Manually by clicking LMB context menu command [Run] - does nothing. Log is following:
I: 27.03.2013 21:03:47: Task executed successfully
I: 27.03.2013 21:04:08: ****** Starting task: Turn off Capslock (imported) ******************
I: 27.03.2013 21:04:08: Executing "1.If Then"
I: 27.03.2013 21:04:08: Executing "2.Send keys to active window"
I: 27.03.2013 21:04:08: Executing "3.End If"
I: 27.03.2013 21:04:08: Task executed successfully

3. Manually by clicking the toolbar button [Run] - does nothing. Log it the same.

4. Manually by pressing the hotkey Ctrl+Enter at a keyboard - does what it should do, that is switch CapsLock off. :o
The log seems to be the same:
I: 27.03.2013 21:25:02: ****** Starting task: Turn off Capslock (imported) ******************
I: 27.03.2013 21:25:02: Executing "1.If Then"
I: 27.03.2013 21:25:02: Executing "2.Send keys to active window"
I: 27.03.2013 21:25:02: Executing "3.End If"
I: 27.03.2013 21:25:02: Task executed successfully

What might it mean? :?
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How to switch on or switch off CapsLock

Post by Oleg »

This task doesn't have any triggers. So you should run this task manually.
The task always turn CapsLock off

Pay attention that this is an demo example only. What do you exactly want to do?
I think that you want to turn CapsLock off automatically. Correct?
Oleg Yershov
leopoldus
Posts: 20
Joined: Fri Oct 22, 2010 11:22 pm

Re: How to switch on or switch off CapsLock

Post by leopoldus »

Oleg wrote:This task doesn't have any triggers. So you should run this task manually.
Well, I see now. However isn't it confusing, that two of the three manually running methods do not work?

Oleg wrote:What do you exactly want to do? I think that you want to turn CapsLock off automatically. Correct?
Yes, that's right. I hate CapsLock and never use it intentionally. So I widh, that when I accidentally press CapsLock or when it does some application, RoboTask should immediately react to changing the status of CapsLock and switch it off again.
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How to switch on or switch off CapsLock

Post by Oleg »

Yes, that's right. I hate CapsLock and never use it intentionally. So I widh, that when I accidentally press CapsLock or when it does some application, RoboTask should immediately react to changing the status of CapsLock and switch it off again.
See the example below. I just attached the expression monitor with {CapsLockState} as expression.
The task turns off CapsLock every time you press CapsLock key

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|2099193306
Comment=STRINGLIST
ContinueOnError=INTEGER|0
Events=FOLDER
ExternalName=STRING|"Task525"
Hide=INTEGER|0
ID=INTEGER|2052485780
LogOnAsUser=INTEGER|1
Name=STRING|"Turn off Capslock"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER

[Actions\Action1]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action1\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{CapsLockState}"

[Actions\Action2]
ActionID=STRING|"A_GENERAL_SENDKEYS"
Enabled=INTEGER|-1
Name=STRING|"Send keys to active window"
Params=FOLDER

[Actions\Action2\Params]
currentwindow=STRING|"1"
fixedwindow=STRING|"1"
keylayout=STRING|"0"
keys=STRING|"{CAPSLOCK}"
pause=STRING|"20"
release=STRING|"0"
sendkind=STRING|"0"
wincaption=STRING|"Notepad"

[Actions\Action3]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Events]
Event1=FOLDER

[Events\Event1]
Enabled=INTEGER|-1
EventID=STRING|"E_VARIABLES_MONITOR"
Params=FOLDER
UnigueID=INTEGER|1634817

[Events\Event1\Params]
case=STRING|"0"
id=STRING|"EALYVZB6"
line00000000=STRING|"{CapsLockState}"
linecount=STRING|"1"
Do not forget to enable this task after importing.
However isn't it confusing, that two of the three manually running methods do not work?
This is the same way - manual launching.
Oleg Yershov
leopoldus
Posts: 20
Joined: Fri Oct 22, 2010 11:22 pm

Re: How to switch on or switch off CapsLock

Post by leopoldus »

Oleg wrote:
Yes, that's right. I hate CapsLock and never use it intentionally. So I widh, that when I accidentally press CapsLock or when it does some application, RoboTask should immediately react to changing the status of CapsLock and switch it off again.
See the example below. I just attached the expression monitor with {CapsLockState} as expression.
The task turns off CapsLock every time you press CapsLock key

Do not forget to enable this task after importing.
Thank you for your code, it really works :D

However for some reason it does not happen every time. Roughly every third or fourth event is going to be skipped :? Have you some ideas of the possible reasons?

And one more remark. RoboTask task launches with noticeable delay up 2-3 seconds after CapsLock status changing (green indicator lights on). Is there any option to reduce this delay time?

However isn't it confusing, that two of the three manually running methods do not work?
This is the same way - manual launching.
Yes, that's just the fact, which confuses me: why the three methods for task manual launching give the different results (or to be more specific, why one of them gives the other result than two remains), although by design the result should be the same for the all of the three manual launching method. Is it a bug or what?
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: How to switch on or switch off CapsLock

Post by Oleg »

Is there any option to reduce this delay time?
Expression monitor checks the expression every second.

Probably we will add the delay time as parameter of the trigger in future.
Oleg Yershov
Post Reply