AutoIt tip of the day: Using Send() within HotKey function

Hi,

I faced an issue almost every time I used Send() function within the function called by HotKeySet() if the HotKey was (Ctrl + Somekey).

I always lift my finger off the Ctrl key as soon as I press the shortcut combination. This causes the Ctrl key to be pressed even after the function called by HotKeySet() finishes execution. I don’t like to keep the Ctrl key pressed for an extra second to avoid the issue.

While I was working on an AutoIt post for my blog, I said let me try to fix this issue.

The solution turned to be simple: use Sleep(250) before using Send() function within the called by HotKeySet() function.

To illustrate, try the two below codes yourself in notepad:

1. The Bad example:

Sleep(250) is not used. Try lifting your finger off Ctrl key as soon as you press Ctrl+M combination. Now do not press Ctrl and use the arrow keys to go through the text. Most of the times, you will find that your PC jumps through the words which means Windows thinks Ctrl key is pressed down. To fix this, just press Ctrl key by itself and Windows will behave normally.

 

2. The Good example:

Sleep(250) is not used. You should not face the above issue again no matter how fast you lift your finger off Ctrl key.

 

Notes:

  • I honestly did not try ControlSend plus I had to use Send() as copy/paste would not work.
  • You don’t have to play with SendKeyDelay or SendKeyDownDelay

Cheers

One thought on “AutoIt tip of the day: Using Send() within HotKey function

Leave a Reply