Hello everyone, I am currently using a mouse click code that I found while browsing the forums. The code is awesome but for some reason, the click isn't recognized sometimes. Maybe 5 out of 10 times the click will happen. Any suggestions?
//declare necessary functions, etc Declare sub CFRelease lib "Cocoa" ( ref as ptr ) 'CGEventRef CGEventCreate ( 'CGEventSourceRef source '); Declare Function CGEventCreate lib "ApplicationServices" (CGEventSourceRef as ptr) as Ptr 'CGPoint CGEventGetLocation ( 'CGEventRef event '); Declare Function CGEventGetLocation lib "ApplicationServices" (CGEventRef as Ptr) as CGPoint 'CGEventRef CGEventCreateMouseEvent ( 'CGEventSourceRef source, 'CGEventType mouseType, 'CGPoint mouseCursorPosition, 'CGMouseButton mouseButton '); '/* mouse events */ ' '#define NX_LMOUSEDOWN 1 /* left mouse-down event */ '#define NX_LMOUSEUP 2 /* left mouse-up event */ '#define NX_RMOUSEDOWN 3 /* right mouse-down event */ '#define NX_RMOUSEUP 4 /* right mouse-up event */ '#define NX_MOUSEMOVED 5 /* mouse-moved event */ '#define NX_LMOUSEDRAGGED 6 /* left mouse-dragged event */ '#define NX_RMOUSEDRAGGED 7 /* right mouse-dragged event */ '#define NX_MOUSEENTERED 8 /* mouse-entered event */ '#define NX_MOUSEEXITED 9 /* mouse-exited event */ Declare Function CGEventCreateMouseEvent lib "ApplicationServices" (CGEventSourceRef as ptr, _ CGEventType as UInt32, position as CGPoint, CGMouseButton as UInt32) as ptr ////////// 'using the other constants above in place of these allows for right clicking, simulating mouse moved 'events, etc ////////// const kCGEventLeftMouseDown = 1 const kCGEventLeftMouseUp = 2 'void CGEventPost ( 'CGEventTapLocation tap, 'CGEventRef event '); Declare sub CGEventPost lib "ApplicationServices" (CGEventTapLocation as UInt32, CGEventRef as ptr) const tapLocation = 0 'CGEventSourceRef CGEventSourceCreate ( 'CGEventSourceStateID sourceState '); Declare Function CGEventSourceCreate lib "ApplicationServices" (CGEventSourceStateID as UInt32) as ptr const kCGEventSourceStatePrivate = -1 //now for the clicking //get mouse location dim CGMouseEvent as Ptr = CGEventCreate(nil) dim mouseLoc as CGPoint = CGEventGetLocation(CGMouseEvent) CFRelease(CGMouseEvent) //create event source dim sourceRef as ptr = CGEventSourceCreate(kCGEventSourceStatePrivate) //press down dim clickMouse as ptr = CGEventCreateMouseEvent(sourceRef, kCGEventLeftMouseDown, mouseLoc, 0) CGEventPost(tapLocation, clickMouse) CFRelease(clickMouse) //release mouse dim releaseMouse as ptr = CGEventCreateMouseEvent(sourceRef, kCGEventLeftMouseUp, mouseLoc, 0) CGEventPost(tapLocation, clickMouse) CFRelease(releaseMouse)