Every now and then, my malfunctioning keyboard spacebar types 2 spaces instead of one. I'd like to automatically correct it with a AHK hotstring.
I looked at A_Space, AutoTrim, etc. without finding a clear way to do it.
How would you replace 2 spaces with one?
Replace 2 space characters with one
Re: Replace 2 space characters with one
Hi,
You should try it with SetTimer.
I cannot test the script now.
Regards
You should try it with SetTimer.
Code: Select all
Space::
if space_presses > 0 ; SetTimer already started, so we log the keypress instead.
{
space_presses += 1
return
}
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
space_presses = 1
SetTimer, Space, -400 ; Wait for more presses within a 400 millisecond window.
return
Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Re: Replace 2 space characters with one
Thanks, but this is rather involved. I was hoping to do it with a single hotstring...
Re: Replace 2 space characters with one
Perhaps this, but there may be some unanticipated drawback (or it might be fine). Cheers.
Code: Select all
:*?b0: ::{Backspace}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Replace 2 space characters with one
It seems to be working. What does *?b0 mean and what sort of drawback were you thinking of?
Re: Replace 2 space characters with one
* ? and b0 are described here:
Hotstrings - Definition & Usage | AutoHotkey
https://autohotkey.com/docs/Hotstrings.htm
My summary:
* and ?: Hotstrings can be triggered without an ending character (*) and inside words (?).
b0: Normally with hotstrings, you type the abbreviation manually, and AutoHotkey then sends backspaces to remove the abbreviation, and AutoHotkey then sends text or does some action(s). b0 prevents sending backspaces.
Re. drawbacks, perhaps you would type too quickly, and get a backspace that deleted the wrong character. Generally speaking you have to test things for a while e.g. a day or so, to see if anything unexpected comes up.
Hotstrings - Definition & Usage | AutoHotkey
https://autohotkey.com/docs/Hotstrings.htm
My summary:
* and ?: Hotstrings can be triggered without an ending character (*) and inside words (?).
b0: Normally with hotstrings, you type the abbreviation manually, and AutoHotkey then sends backspaces to remove the abbreviation, and AutoHotkey then sends text or does some action(s). b0 prevents sending backspaces.
Re. drawbacks, perhaps you would type too quickly, and get a backspace that deleted the wrong character. Generally speaking you have to test things for a while e.g. a day or so, to see if anything unexpected comes up.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Replace 2 space characters with one
I had the same idea with backspace, but in my opinion it is a risky solution.
What if he uses space in a game or for other applications?
Regards
What if he uses space in a game or for other applications?
Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09