Page 1 of 1

Send Clipboard content when key not in object?

Posted: 16 May 2022, 12:46
by Krd
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": "bannas@fruits.mars", "An apple": "apples@fruits.mars"}
MsgBox % email[Clipboard]
;SendInput % email[Clipboard]
return
How to turn to something like this that works:

Code: Select all

F12::
email := {"A banana": "bannas@fruits.mars", "An apple": "apples@fruits.mars"}
If (email ~= Clipboard)
MsgBox, % email[Clipboard]
else
MsgBox, % Clipboard
return

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

Posted: 16 May 2022, 13:14
by mikeyww

Code: Select all

email := {"A banana": "bannas@fruits.mars", "An apple": "apples@fruits.mars"}
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.

Re: Send Clipboard content when key not in object?

Posted: 16 May 2022, 15:00
by Krd
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 :)