Page 1 of 1

Prevent accidental capslock press

Posted: Mar 13th, ’20, 17:37
by prasad383
Accidental Capslock presses are annoying while typing, at least for me..
Following script ignores the accidental Capslock press and toggles Capslock state on or off only when you press and hold it for a certain time period, for eg. 0.5 second.. This might be useful for someone like me out there.. This is not my script-- i have copied from net and modified it.

Code: Select all

$Capslock::

KeyWait, CapsLock, T0.5      ; half a second - change to your preference
If ErrorLevel
{
   	if GetKeyState("CapsLock", "T") = 1
	{
		SetCapsLockState, off 
		soundbeep, 100, 100
	}
	else if GetKeyState("CapsLock", "F") = 0
	{
		SetCapsLockState, on
		soundbeep, 100, 100
	}
}
Else 
   return


Re: Prevent accidental capslock press

Posted: Mar 15th, ’20, 21:00
by Tom
Very useful script, thanks for posting.

Re: Prevent accidental capslock press

Posted: Jan 30th, ’21, 19:47
by SafeTex
Hello

When I try to install the capslock press script in this thread, I get an error

Error at line 14
The following variable name contains an illegal character
",UseErrorLevel"

I'm a complete novice !!

Thanks

Re: Prevent accidental capslock press

Posted: Jan 30th, ’21, 20:36
by Tom
To make this script work in FastKeys, you need to set
Type: Command
Shortcut: Capslock (click ... button and enable $ Hook attribute)
Command:

Code: Select all

KeyWait, CapsLock, T0.5      ; half a second - change to your preference
If ErrorLevel
{
   	if GetKeyState("CapsLock", "T") = 1
	{
		SetCapsLockState, off 
		soundbeep, 100, 100
	}
	else if GetKeyState("CapsLock", "F") = 0
	{
		SetCapsLockState, on
		soundbeep, 100, 100
	}
}
Else 
   return

Re: Prevent accidental capslock press

Posted: Jan 31st, ’21, 09:35
by SafeTex
Hello Tom :D

Well I've got the thing to install but it does not seem to be working on the half a second principal
Can you explain to me please how to change the time?

Also, I tried installing a second script last night and got errors again
I tried both copying the script and installing the .ahk macro but it made no difference

I'll try again today with the hook but what are the rules to follow in general for installing "code" from the forum?

The scripts make little sense to me when I try to manipulate them.

Thanks in advance for any help

Re: Prevent accidental capslock press

Posted: Jan 31st, ’21, 10:21
by Tom
You should be able to run the majority of the scripts from the forum using two alternative methods:

1. Using Type: Command and copy the code into the command field.
2. Using Type: Run (or Script in previous versions) and selecting the .ahk file from the disk.

In both cases you have to remove the shortcuts, hotstrings etc. definitions from the code (as in my example) as you are defining them in FastKeys.

I recommend to get familiar with the basic AutoHotkey programming first. You may also check many preset scripts in the Library.

Re: Prevent accidental capslock press

Posted: Feb 1st, ’21, 08:51
by SafeTex
Hello Tom :D

I managed to get one of the two scripts to work with your help (prevent accidental caplock press)
I think the removal of shortcuts, hotstrings etc. definitions etc. was one of my problems and the hook in Fastkeys which I don't really understand yet
On the other script (changing accented letters) I've posted again to ask for more help if you have the time

Finally, I was hoping to skip the ahk lessons but I've started them now

Thanks for all your help