Adding additional letters without holding a key

Get help with using AutoHotkey and its commands and hotkeys
bkvstar
Posts: 2
Joined: 10 Jan 2020, 08:01

Adding additional letters without holding a key

10 Jan 2020, 08:20

Hi, I'm trying to add additional letters to my keyboard.

Code: Select all

#If GetKeyState("CapsLock", "T")
{
Launch_App2 & e:: ;
	If GetKeyState("Shift", "p")
	Send {U+011B}
	else
	Send {U+011A}
	return
}


#If NOT GetKeyState("CapsLock", "T")
{
Launch_App2 & e:: ;
	If GetKeyState("Shift", "p")
	Send {U+011A}
	else
	Send {U+011B}
	return
}
This works as intended, I hold down my "Launch_App2" (calculator) key and e-key and it produces the letter I want.

What I want to do is that when I press (not hold) "Launch_App2" and after that in some short time (like 0.5 seconds) I press down e-key it does what I want. It's basically a dead key that expires after some time.

My idea was to have a value that is initally zero, when I press then "Launch_App2" it sets it to 1 for half a second and then back to 0. Then I would have a simple if-else statement that would check if value is 0 or 1 and send "e" or modified e.
I tried some things but nothing worked. Could someone help me with this?
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Adding additional letters without holding a key

10 Jan 2020, 10:15

Does this work?

Code: Select all

#SingleInstance, Force
#Persistent

KeyToggle := 0

Launch_App2::
	KeyToggle := 1
	SetTimer, KeyTimer, -500
return

KeyTimer:
	KeyToggle := 0
return

#If (KeyToggle = 1)
e::
	Send, % (GetKeyState("CapsLock", "T") ? (GetKeyState("Shift", "P") ? "{U+011B}" : "{U+011A}") : (GetKeyState("Shift", "P") ? "{U+011A}" : "{U+011B}"))
return	
#If
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
bkvstar
Posts: 2
Joined: 10 Jan 2020, 08:01

Re: Adding additional letters without holding a key

10 Jan 2020, 14:48

TheDewd wrote:
10 Jan 2020, 10:15
Does this work?
Thanks a lot, this works perfectly. I didn't write it in my request, but I wanted the toggle to be on for a maximum of one key press so I added the additional "KeyToggle := 0" line below "Send..." line.

I know it's unrelated to the original question, but could you please explain what does the empty "#If" do?

EDIT:
Sorry, but I've only now realized it only works partly. Without shift, caps and no caps work fine, but with shift it just prints "e" or "E".
I fixed it by adding a hotkey for "+e" and removing the GetKeyState for shift.

FInal code:

Code: Select all

#SingleInstance, Force
#Persistent

KeyToggle := 0

Launch_App2::
	KeyToggle := 1
	SetTimer, KeyTimer, -500
return
	
KeyTimer:
	KeyToggle := 0
return

#If (KeyToggle = 1)
e::
	Send, % (GetKeyState("CapsLock", "T") ? "{U+011A}" : "{U+011B}")
	KeyToggle := 0
return

+e::
	Send, % (GetKeyState("CapsLock", "T") ? "{U+011B}" : "{U+011A}")
	KeyToggle := 0
return
#If

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], Clemens375, euras, Google [Bot], songdg and 258 guests