How to get touchscreen events for windows

I am trying to make my application work with the touch screen on the surface pro.

I am currently using a slightly modified ofEasyCam and I would like to be able to pinch zoom at a minimum / or some sort of finger combination to do the same as the right mouse button drag.

Simply dragging one finger has the same effect left dragging with the mouse which is good. But I need someway to capture the pinch/zoom or 2 finger drag in order to be able to zoom.

I can’t really find any information in OpenFrameworks regarding using touchscreens in windows so I was wondering if there are any instructions on how I might get started?


Currently the desktop windowing system we are using by default (GLFW) doesn’t support multi-touch input / gestures.

GLFW will someday support multitouch, but not yet.

You may be able to use something like this:

If not, have a look around

There are several addons that demonstrate various approaches on different platforms.

1 Like

thanks , am looking at ofxWinTouch .

1 Like

In case anyone else is going down this path:

I got it working with my opengl app as follows.

ofxWinTouch seems to be broken and I cant get it to build , but I was able to use GestureEngine.cpp from that project which essentially most most of the gesture event handling seems to be done. Kudos to the author of that.

You have to hack your app to receive windows messages , and pass gesture messages to GestureEngine.cpp before passing other messages to the current windows event handler (ofappglutwindow?). So the way I accomplished this is to do something very similar to what ofAppGlutWindow already does in fixCloseWindowOnWin32. For my case I simply
changed ofApp.cpp:

#include "GestureEngine.h"

static CGestureEngine* s_GestureEngine;
static WNDPROC currentWndProc;
static HWND handle  = NULL;
static LRESULT CALLBACK interceptWinProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)


      case 0x0119 /*WM_GESTURE*/:
		  s_GestureEngine->WndProc(hwnd, wParam, lParam);
	  case 0x0240 /*WM_TOUCH */:
         return CallWindowProc(currentWndProc, handle, Msg, wParam, lParam);

    return 0;

//store the current message event handler for the window
inline void Win32TouchHackStartup()
	s_GestureEngine = new CGestureEngine();
	handle = WindowFromDC(wglGetCurrentDC());
	currentWndProc = (WNDPROC)GetWindowLongPtr(handle, GWL_WNDPROC);
	SetWindowLongPtr(handle, GWL_WNDPROC, (long)interceptWinProc);

inline void Win32TouchHackShutDown()
	delete s_GestureEngine;


inline void Win32TouchHackStartup(){}
inline void Win32TouchHackShutDown(){}


Now modify setup to use the hack

//now modify setup:

Finally its a matter of doing the work in GestureEngine::ProcessMove for example. In my code I didnt want to have to derive from CGestureEngine , so i removed all the virtuals , made and interface class and defined the function

void CGestureEngine::ProcessMove( const LONG ldx, const LONG ldy )
	m_GestureInterface.ProcessMoveGesture(ldx, ldy);

GestureInterface feeds to my camera system (modified from ofEasyCam). In the case of PanGesture:

void Cam::PanGesture(long dx, long dy)
	float gestureSensitivityX = 1.0f;
	float gestureSensitivityY = 1.0f;
	moveX = -dx * gestureSensitivityX * (getDistance() + FLT_EPSILON)/viewport.width;
	moveY =  dy * gestureSensitivityY * (getDistance() + FLT_EPSILON)/viewport.height;

	//printf("orig y = %d, x = %f , y= %f\n", dy, moveX, moveY);

Would you let me know what’s broken for you in ofxWinTouch and maybe file an issue? I’ve got it working on my Surface, would like to fix it to be more easily useable.


Just posting this here in case anyone else needs native multitouch for the default GLFW on Windows. There’s a ‘touch’ branch of GLFW on github ( that has all the handles for multitouch. It takes a bit of tweaking to get working with OF (recompile and replace glfw libs/headers and edit ofAppGLFWWindow with native touch callbacks, events, etc), but I can confirm this works on Windows 7 + 8.

Hopefully GLFW will merge this branch into their main master soon, then we could make it part of the OF core.

Here’s a zip with the recompiled glfw (for vs2012), edited ofAppGLFWWindow and example ofApp… (77.4 KB)


@trentbrooks the zip file broken,any chance upload it again? thxs

@liquid no worries… (77.4 KB)

Actually looks like uploads are not working. Try here:

1 Like

thxs for the help, but this version of GLFW not compatible with OF 090. will post here if i can manually merge with current version

Hey @liquid, I just revisited this for an OF 090 / windows 8 project. Found a way to use ‘Hooks’ on Windows to get the window events without modifying OF or GLFW. Here’s an addon/example:

@trentbrooks,thxs for the help,i’m also found this addons which using wm_pointer api,haven’t try it though.

1 Like

Oh man, wish i saw that addon a few days ago. Same results i guess. Added a define to my example so you can switch between WM_POINTER and WM_TOUCH- Just had to change the Windows Hook key code.

sorry for bring this topic up. ofxwintouchhook works great on windows10. but it cannot get touch event on windows7. i’m using Windows7 SP1, VS2015, OF0.9.0.

In ofxWinTouchHook.h, if I do not comment #define USE_WM_POINTER_EVENTS, there is runtime error saying: “unable to find an entry point named GetPointerInfo in USER32.dll”. If I comment out #define USE_WM_POINTER_EVENTS, it can run but it just cannot get touch event. Could you give me some advice? Thank you so much!

Hey I have the same problem. Have you found the solution? I really need to run this addon on windows 7 with oF version 0.9.8