SendKeys from an array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
eramark123
Posts: 2
Joined: 16 Jun 2017, 12:02

SendKeys from an array

16 Jun 2017, 12:16

Okay i dont know my way around AHK but basicly i have an array of web links :
Link1
Link2
Link3
Link4

Now what i want to do is to set them up like so that :
- If i press Numpad1 it will type the first link
- If i press Numpad2 it will type the second link
and so on.

What i am currently using is this but it can only output one link :

Code: Select all

^!t:: ;<-- ctrl-alt-t activates the event
Toggle := !Toggle ;<-- is toggleable
If (!Toggle) ;
   return
word = http://bit.ly/2tuhKXv ;
send %word%{enter} ;
Return ;
So in the above case, when i press CTRL+ALT+T it will type the link (word). But i want to make this a bit bigger so i have no need to change the link every single time.
Thanks for in advanced!
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: SendKeys from an array  Topic is solved

16 Jun 2017, 12:20

This is a strange way to accomplish what you described, but it works:

Code: Select all

Links := []
Links["Numpad1"] := "http://bit.ly"
;.
;.
;.

^!t::Toggle := !Toggle ;<-- is toggleable

#IF (Toggle)
Numpad1::
Numpad2::
;.
;.
;.
Send, % Links[A_ThisHotkey] . "{Enter}"
Toggle := False
Return
#IF
eramark123
Posts: 2
Joined: 16 Jun 2017, 12:02

Re: SendKeys from an array

16 Jun 2017, 12:28

Nightwolf85 wrote:This is a strange way to accomplish what you described, but it works:

Code: Select all

Links := []
Links["Numpad1"] := "http://bit.ly"
;.
;.
;.

^!t::Toggle := !Toggle ;<-- is toggleable

#IF (Toggle)
Numpad1::
Numpad2::
;.
;.
;.
Send, % Links[A_ThisHotkey] . "{Enter}"
Toggle := False
Return
#IF
This is perfect, simple and it works like a charm.
Thanks! :superhappy:
User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: SendKeys from an array

16 Jun 2017, 12:41

Here's a quick and dirty demo of using an associative array to associate the numpad keys with urls

Code: Select all

SendMode,Input
urls := {Numpad1:  "www.microsoft.com", Numpad2: "www.google.com", Numpad3: "www.yahoo.com"}

Numpad1::
Numpad2::
Numpad3::
	MsgBox % urls[A_ThisHotkey]
return

Esc::
  ExitApp
Edit: Nightwolf85 beat me to it with a more practical demonstration. :bravo:
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 138 guests