Alex Gordon
Alex Gordon

Reputation: 60741

Closing a window using key combinations

I've mapped the following keys:

ALT + Z to be equivalent to ALT + F4
ALT + X to be equivalent to ALT + F + C

With the following code:

!z::
   Send, !{F4}
!x::
   Send, !fc

However, when this code is running and I press ALT + Z , the actual keys that are being sent are:

ALT + F4 and then ALT + F + C instead of just ALT + F4

What am I doing wrong? How do get the mapping to be correct for ALT+Z?

Upvotes: 0

Views: 74

Answers (2)

Schneyer
Schneyer

Reputation: 1257

You need a return statement to tell the script to stop execution

!z::
   Send, !{F4}
return

!x::
   Send, !fc
return

Upvotes: 2

MrAutoIt
MrAutoIt

Reputation: 795

This is an AutoIt solution that works for me.

HotKeySet("!z", "sendKeys")

; Run Notepad just to have something to test with.
Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

While 1
    Sleep(100)
WEnd

Func sendKeys()
    Send("!{f4}")
    Exit
EndFunc   ;==>sendKeys

Upvotes: -1

Related Questions