How to trigger INPUT without a hotkey?

Get help with using AutoHotkey and its commands and hotkeys
Heezea
Posts: 53
Joined: 30 Sep 2013, 21:33

How to trigger INPUT without a hotkey?

27 Aug 2014, 17:36

Hey guys, I have something that's working pretty well, but it requires me to tie a hotkey that is the first letter of each word I want to use with the INPUT functionality. How can I make the first letter simply part of the input match list and still have things fire when I press the relevant key combination?

I appreciate any help, thanks.

Please see working/testing script below.

Code: Select all

#SingleInstance Force
#InstallKeybdHook 
#InstallMouseHook

LoadNumberList()

Loop
{
	sleep 100
	
}

Numpad5::
	ExitApp

Numpad6::
	Reload
return

Numpad8::
	ActiveWindowToReturnTo := WinExist("A")
	WinActivate ahk_class SciTEWindow ahk_exe SciTE.exe
	WinWait, ahk_class SciTEWindow ahk_exe SciTE.exe,, 2
	SendInput {F5}
	sleep 10
	WinActivate ahk_id  %ActiveWindowToReturnTo%
return

;MS Word shortcuts
#IfWinActive ahk_class Notepad
{	
	~d::
		InputToTypeAndNumber()
	return

	~w::
		InputToTypeAndNumber()
	return

	~m::
		InputToTypeAndNumber()
	return

	~y::
		InputToTypeAndNumber()
	return
}
#IfWinActive


InputToTypeAndNumber()
{
	global
	
	Input, InputFromKeyBoard, T4 V, , %NumberList%
	if (ErrorLevel = "Timeout")
	{
		TTMsg("Timed out.", 1000)
		return
	}

	If InputFromKeyBoard in %NumberList%
	{
		StringLen, InputLen, InputFromKeyBoard
		InputLen := InputLen + 1
		StringTrimLeft, ItemType, A_ThisHotkey, 1
		ItemTypes := {D: "Day", W: "Week", M: "Month", Y: "Year"}
		ItemType := ItemTypes[ItemType]
		ItemTypeAndNumber := ItemType . " " . InputFromKeyBoard
		SendInput, {Backspace %InputLen%}%ItemTypeAndNumber% 
		InputFromKeyBoard := ""
		TTMsg(ItemTypeAndNumber, 1000)
	}
	return
}

LoadNumberList()
{
	global NumberList
	
	Loop, 20
	{
		NumberList := NumberList . A_Index . " ,"
	}
	StringTrimRight, NumberList, NumberList, 1
	return NumberList
}	

TTMsg(Message, Timer) ;example TTMsg("Testing", 1000)
{
	MouseGetPos ttX, ttY
	ToolTip, %Message%, ttX + 50, ttY + 50
	SetTimer, RemoveToolTip, %Timer%
	return 
}

RemoveToolTip:
		SetTimer, RemoveToolTip, Off
		ToolTip
		return


User avatar
dmg
Posts: 287
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: How to trigger INPUT without a hotkey?

27 Aug 2014, 22:22

OK. You say "requires me to tie a hotkey that is the first letter of each word I want to use with the INPUT functionality" but that doesn't really tell us much. You say what you wish your code did not require, but you did not say what your code is intended to do, what you want it to do. Unless we take apart your code to figure out what it is intended to do we can't figure ot how to change it.

Can you explain what you are trying to do, and what it is doing that you don't like?
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
Heezea
Posts: 53
Joined: 30 Sep 2013, 21:33

Re: How to trigger INPUT without a hotkey?

28 Aug 2014, 06:23

As an example, if I want to type Month 1, I type "M1 ", which then fills out to "Month 1 ". The issue I have is that "M" is a HOTKEY that readies the INPUT part "1 ", so for each word I want to add to my list of auto-completing words, I need to add the first letter as a hotkey. This is not a huge problem necessarily, but seems cumbersome. Is there a way around this where I can have the entire "M1 " handled by the INPUT rather than HOTKEY + INPUT?

So phrased differently, I can't figure out how to get INPUT to work without using a hotkey to get it into a "ready state".
Heezea
Posts: 53
Joined: 30 Sep 2013, 21:33

Re: How to trigger INPUT without a hotkey?

28 Aug 2014, 07:48

I've used hotstrings and they work well, but I don't want to use them for the same reason I don't want to use hotkeys. Namely, that I'd have to create 80 Hotstrings to capture (Day, Week, Month, Year = 4 choices) * (1 - 20 = 20) = 80 choices. If I ever want to add more choices, with INPUT, I just change a few digits or add a column to my array, but with Hotstrings, I'd have to manually add each item to the code.
HotKeyIt
Posts: 2144
Joined: 29 Sep 2013, 18:35
Contact:

Re: How to trigger INPUT without a hotkey?

28 Aug 2014, 09:26

Then you can use Loop + Input to wait for the right key to be pressed:

Code: Select all

Loop {
  Input,key,VL1
  If (key="w"){
    ;...
  }
  ;...
}
Heezea
Posts: 53
Joined: 30 Sep 2013, 21:33

Re: How to trigger INPUT without a hotkey?

28 Aug 2014, 13:30

Ok thanks a bunch. I had used this method, but I was a bit concerned about running a continuous loop and it eating up resources. I'd tried it with a 10ms pause and it would occasionally miss my key presses, but without any pause it should work fine.

Do you have any feedback regarding a continuous loop eating up memory/resources? Is this a real concern, or not anything to worry about?

Thanks again for your help.
User avatar
Nextron
Posts: 1377
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: How to trigger INPUT without a hotkey?

28 Aug 2014, 16:07

Also, it's not continuously looping. It waits at the input command until you input a character.

You might want to look into dynamic hotstrings, with which you can use regex to set up your hotstrings. It doesn't use input, but creates hotkeys for every keyboard key, which I don't really like. I once substituted those for the input command, but breaks the internal requirement to detect mouse buttons. I haven't gotten around to fixing that.

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot] and 23 guests