Increase mouse polling rate, or get raw mouse data


#1

Hi,
I’m developing an application in which I’d like to poll mouse data at higher than the screen update rate. Is there any way to do this in openframeworks - it looks to me as though mouse is polled at no higher than screen update rate.

Alternatively any advice on polling raw mouse data while working with openframeworks? Either Linux or win 10?


#2

hi! i will have the same needs in future for some things i’ll like to develop. I was thinking about totally disabling mouse/touch input from oF and using this (or something similar) instead:

someone here knows how to disable/unregister mouse/touch events?


#3

one way of doing this is to create your own ofMainLoop instead of letting OF create a default one so you can have control over how events are called:

in main.cpp:

int main()
{
    ofGLFWWindowSettings settings;
    ofCreateWindow(settings);

    auto mainloop = make_shared<ofMainLoop>();
    mainloop->run(window, make_shared<ofApp>());
    ofSetMainLoop(mainloop);

    while(true){
        mainloop->loopOnce();
        ofAppGLFWWindow::pollEvents();
    }
    return 0;
}

That example never ends, you would need to listen the exit event and if you want the key event for a escape key and when they are triggered exit the while loop.

Also in this example pollEvents is still called only once.

In linux you can simply call mainLoop->pollEvents() from a different thread at whatever rate you want using an ofTimer for example:

int main()
{
    ofGLFWWindowSettings settings;
    ofCreateWindow(settings);

    auto mainloop = make_shared<ofMainLoop>();
    mainloop->run(window, make_shared<ofApp>());
    ofSetMainLoop(mainloop);

    auto eventpoll = std::thread([mainloop]{ 
         ofTimer eventsTimer;
         eventsTimer.setPeriodicEvent(5*1000*1000);
         
         while(true){
             ofAppGLFWWindow::pollEvents();
             eventsTimer.waitNext();
         }
    });

    while(true){
        mainloop->loopOnce();
    }
    return 0;
}

which will trigger an event poll every 5ms. Again you would need a condition to exit the events poll loop as well

in win and osx it seems it’s more complicated cause the event poll can only be done in the main thread. supposedly you could draw on a different thread (creating the window on a different thread) and call pollEvents from the main thread. there’s a more detailed explanation here: http://discourse.glfw.org/t/multithreading-glfw/573/5


#4

Thanks both - really helpful. Gainput looks particularly good for my purposes, with a poll running in a separate thread.