Hotkey to move mouse and click I'm currently using Keyboard maestro to create a macro that allows me to move the cursor to certain coordinates and perform a left click.

Unfortunately under Yosemite it doesn't work as expected, since it clicks sporadically (it always moves the cursor but doesn't click everytime).

Are there any other viable options to achieve this? It would be great if I can set coordinates relatively to active window.
As an Adaption from @mat-burns code in this post
( Note You'll also need xcode installed. )

       #!/usr/bin/env xcrun swift

import Foundation

let kDelayUSec : useconds_t = 500_000

func moveMouseClick( p1: CGPoint) {

    let mouseMove = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseDragged), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
    let mouseDown = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseDown), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
    let mouseUp = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseUp), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()


    CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseMove)
    usleep(kDelayUSec)
    CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseDown)
    usleep(kDelayUSec)
    CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseUp)
}


func main() {

    let pointX = 396
    let pointY = 214

    let p1 = CGPointMake( CGFloat(pointX),  CGFloat(pointY))
    moveMouseClick( p1)


}

main()


Change the lines:

let pointX = 396
let pointY = 214


to reflect you click point.

Save this code down as moveClick.swift

And then in Terminal.app run /bin/chmod +x ~/scripts/moveClick.swift to make the script executable

Change ~/scripts/moveClick.swift to your actual path to your swift file.

I do not have Keyboard maestro But I see it can execute a shell script.

Execute a Shell Script Action

~/scripts/moveClick.swift



In the example above we have hard coded the click point. 

But if you want to make it versatile, we can make the code take arguments.

Using this code instead.

    #!/usr/bin/env xcrun swift

import Foundation

let kDelayUSec : useconds_t = 500_000

func moveMouseClick( p1: CGPoint) {

    let mouseMove = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseDragged), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
    let mouseDown = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseDown), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()
    let mouseUp = CGEventCreateMouseEvent(nil, CGEventType(kCGEventLeftMouseUp), p1, CGMouseButton(kCGMouseButtonLeft)).takeUnretainedValue()


    CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseMove)
    usleep(kDelayUSec)
    CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseDown)
    usleep(kDelayUSec)
    CGEventPost(CGEventTapLocation(kCGHIDEventTap), mouseUp)
}


func main() {

    let p1 = CGPointMake( CGFloat(atof( C_ARGV[1])),  CGFloat(atof( C_ARGV[2])))


    moveMouseClick( p1)


}

main()


Again in Keyboard maestro.

Execute a Shell Script Action

~/scripts/moveClick.swift 396, 214