Prevent accidental capslock press

Share your favorite FastKeys commands
Post Reply
prasad383
Posts: 19
Joined: Oct 18th, ’19, 14:43

Post by prasad383 » Mar 13th, ’20, 17:37

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

User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Mar 15th, ’20, 21:00

Very useful script, thanks for posting.
SafeTex
Posts: 12
Joined: Mar 21st, ’20, 09:05

Post by SafeTex » Jan 30th, ’21, 19:47

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
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Jan 30th, ’21, 20:36

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
SafeTex
Posts: 12
Joined: Mar 21st, ’20, 09:05

Post by SafeTex » Jan 31st, ’21, 09:35

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
User avatar
Tom
Posts: 791
Joined: Nov 24th, ’15, 23:39

Post by Tom » Jan 31st, ’21, 10:21

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.
SafeTex
Posts: 12
Joined: Mar 21st, ’20, 09:05

Post by SafeTex » Feb 1st, ’21, 08:51

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
Post Reply