Send Clipboard content when key not in object? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Send Clipboard content when key not in object?

Post by Krd » 16 May 2022, 12:46

Hey,

I have now with help of Mikeyww got this in action. But there are several cliboard contents which do not yet exist as a key or value in object. And I do want to create them manually in the list later.

Code: Select all

F12::
Clipboard := "A kiwi"     ;Or any other fruit that is not yet in the list, so it could be anything, no way to know all beforehand. 
email := {"A banana": "[email protected]", "An apple": "[email protected]"}
MsgBox % email[Clipboard]
;SendInput % email[Clipboard]
return
How to turn to something like this that works:

Code: Select all

F12::
email := {"A banana": "[email protected]", "An apple": "[email protected]"}
If (email ~= Clipboard)
MsgBox, % email[Clipboard]
else
MsgBox, % Clipboard
return

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Send Clipboard content when key not in object?  Topic is solved

Post by mikeyww » 16 May 2022, 13:14

Code: Select all

email := {"A banana": "[email protected]", "An apple": "[email protected]"}
F12::
matched := False
For fruit, address in email
 SendInput % (match := fruit ~= Clipboard, matched |= match) ? "{Text}" address : ""
SendInput % matched ? "" : "{Text}" Clipboard
Return
~= is regex match rather than exact comparison.

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Send Clipboard content when key not in object?

Post by Krd » 16 May 2022, 15:00

Finger and arm saver mikeyww! Now my mice fingers can relax a bit :lol:

Thank you so much.

I really appreciate your great support across whole forums :)

Post Reply

Return to “Ask for Help (v1)”