BlackBerry long-press: Long-holding a key will substitute the “upper-level” of that key

In today’s webinar Dale showed us an example of a script he made which helps him put the “upper-level” of any given key (so if he long-holds “a” it will replace it with “A”.  If he long-holds 3 it will replace it with “#”.  I don’t have a copy of Dale’s work, but Cap’n Odin rewrote it to the below.  I think this is a great example of how there are different ways to solve a problem.   Also, this is the second version Cap’n Odin did.  The first one worked but he realized there was a better/simpler approach and re-wrote the script to reflect this new “better” approach.

Thanks again to both Dale, for sharing his original code and the idea and Cap’n Odin for his work during the webinar!

shift := []

Loop 10 {
	shift.Push(A_Index - 1)
}

Loop % Asc("z") - Asc("a") + 1 {
	shift.Push(Chr(Asc("a") + A_Index - 1))
}

for i, key in shift {
	fun := Func("KeyPressed").Bind(key, 300)
	Hotkey, % "$" key, % fun
}

KeyPressed(key, duration) {
	time := A_TickCount
	While(GetKeyState(key, "P")) {
		if(A_TickCount - time > duration) {
			Break
		}
		Sleep, 25
	}
	Send, % A_TickCount - time > duration ? "+" key : key
	KeyWait, % key
}

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.