views:

39

answers:

1

Hi,

By default on Windows, when copying text, it gets put in the clipboard. But when attempting to copy empty text, the clipboard is untouched. For example, selecting no text in your editor, then hitting ctrl+c, will cause no change in the clipboard.

Problem is, I need to catch this event with AutoHotKey. Since the clipboard is unchanged, I have no idea how to do this cleanly (without a timeout, that is).

Does anyone have any idea how to do this?

Edit: To clarify, I'm sending the ctrl+c from within AutoHotKey. I'm doing so to tell if any text is selected, i.e., I'm sending ctrl+c, then checking if any text was copied to the clipboard or not. Problem is, if no text is selected, the clipboard handlers for AutoHotKey never get called, forcing me to use a timeout, which isn't good practice.

A: 

Maybe you should hotkey the Ctrl + C instead, that way any time that hotkey is pressed you will know.

You might want to make sure to send the normal Ctrl + C action to windows so you can copy. consider this example:

~^c::
msgbox, % "Clipboard Changed even if you didnt copy anything"
        . "(...not really but you tried at least)"
return

That message will fire up every time you press Ctrl + C even if you didnt copy anything to the clipboard. At the same time you will be sending the native function of Ctrl + C to windows so your clipboard WILL change if you copied something.

From the help file:

~: When the hotkey fires, its key's native function will not be blocked (hidden from the system).

You might want to also have an onClipboardChange to check when the clipboard really changed.

RaptorX
The problem is, I'm programatically sending the ctrl+c, and I want to see if text is captured. I'm using it to check programatically if there is a selection (i.e., is text selected right now, or not). So this solution doesn't help me, since I already know the ctrl+c is being sent, since I'm the one sending it! Thanks for the creative idea though, I'll edit the question to make it clearer.
Edan Maor