Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Global Mouse Hooking for Mac OS

Global Mouse Hooking for Mac OS

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Himanshu Rohilla
    wrote on last edited by
    #1

    Hello everyone,

    I want the mouse events like Mouse Move, Mouse Up, Mouse Down globally means also find out these events outside the application on the Mac OS. I have some code which execute perfect with the Cocoa Application. But, when i use that code in Qt Application, It does not work. THis is my code.

    @#include <QDebug>

    #include <CoreFoundation/CoreFoundation.h>
    #include <ApplicationServices/ApplicationServices.h>

    extern CGEventRef handleCGEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef eventRef, void *refcon);

    CGEventRef handleCGEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef eventRef, void *refcon)
    {
    if (type == kCGEventLeftMouseDown )
    {
    qDebug() << "kCGEventLeftMouseDown";
    }
    else if(type == kCGEventLeftMouseUp)
    {
    qDebug() << "kCGEventLeftMouseUp";
    }
    else if(type == kCGEventMouseMoved)
    {
    qDebug() << "kCGEventMouseMoved";
    }

    return eventRef;
    

    }

    CMouseEvent::CMouseEvent(QObject *parent) :
    QObject(parent)
    {
    CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, kCGEventMaskForAllEvents, handleCGEvent, NULL);
    CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
    CFRunLoopAddSource(CFRunLoopGetMain(), runLoopSource, kCFRunLoopCommonModes);
    CGEventTapEnable(eventTap, true);
    }
    @

    This is a class which is used for mouse events. I am creating an object of this class in main() function. My application is console application.

    When i run this code, it stuck in the code. I don't know where it stuck. Mouse only move but unable to click anywhere.

    Thanks in advance....

    HImanshu Rohilla

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved