Paul McCabe
asked on
AutoHotKeys: Condition for "empty clipboard" and MsgBox with no buttons
Hello, I am using AutoHotKeys (AHK) to make Control + P to paste the content of the clipboard and then immediately clear it. The idea is to not leave sensitive information such as passwords hanging around on the clipboard. Basic functionality using the script below is working OK:
; Paste and clear clipboard with Control + P
^p up::
send ^{v}
sleep 100
clipboard := ""
MsgBox, 0, Notice, Clipboard cleared, 1
return
But I am tryng to improve it in two ways:
1. Not have the message appear if there is nothing on the clipboard to be pasted (or alternatively have another message "Clipboard is empty" appear).
2. Remove the "OK" button from the message box (since the message autodisappears it is not needed)
Regarding 1. I have tried all sorts of If....Else variations but just cannot seem to get the condition for "empty clipboard" right.
Regarding 2. maybe this is just not possible going by AHK's documentation https://autohotkey.com/docs/commands/MsgBox.htm. But if anyone has alternative ideas they would be appreciated.
I am using the latest version of AHK ( v1.1.30.00 ) on Windows 10 Pro. Thank you in advance for any comments.
; Paste and clear clipboard with Control + P
^p up::
send ^{v}
sleep 100
clipboard := ""
MsgBox, 0, Notice, Clipboard cleared, 1
return
But I am tryng to improve it in two ways:
1. Not have the message appear if there is nothing on the clipboard to be pasted (or alternatively have another message "Clipboard is empty" appear).
2. Remove the "OK" button from the message box (since the message autodisappears it is not needed)
Regarding 1. I have tried all sorts of If....Else variations but just cannot seem to get the condition for "empty clipboard" right.
Regarding 2. maybe this is just not possible going by AHK's documentation https://autohotkey.com/docs/commands/MsgBox.htm. But if anyone has alternative ideas they would be appreciated.
I am using the latest version of AHK ( v1.1.30.00 ) on Windows 10 Pro. Thank you in advance for any comments.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're very welcome, Paul. I'm glad to hear that it works for you. When using AutoHotkey to send keystrokes, there's always the issue of Sleep times. It takes some experimentation to get them right, and it varies from system to system. For example, I tested my script here before posting it and it worked perfectly every time (numerous times) without a Sleep after the paste. But I'm glad you figured out that a Sleep,100 does the trick for you. Regards, Joe
ASKER
Got you on points 3 and 4. Also point 5, although personally I never Ctrl + P for printing. Again, many thanks !