The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Windows 7 touch screen and SDL 1.2.14
Zeemvel


Joined: 07 Nov 2010
Posts: 3
Hi,

First of all, I'm not interested in multitouch or anything. All I want is that if someone uses a Windows 7 touch screen instead of a mouse, that it also still works with regular mouse events.

However, when receiving the SDL_MOUSEBUTTONDOWN event in this case, the x and y coordinate of the event are incorrect. They are a previous click position instead of the current one.

I realize that on a touch screen the mouse doesn't move, the finger just jumps from one place to another and clicks somewhere. But when the mouse down event (finger down) is received, I would expect it to know the x and y position.

I really need to know the correct x and y position there, otherwise my application doesn't work on this touchscreen, because when someone clicks on a button on the screen, my application thinks they clicked another button at another location instead of the correct one...

Is this an SDL bug?
lan.chih.hung


Joined: 05 Feb 2011
Posts: 1
Hi Zeemvel,

Last week I got the same problem like you. But I have wrok around it.

There are two way.

way 1. change to SDL 1.3

way 2. copy some code from SDL 1.3. make patch at SDL 1.2 and rebuild SDL 1.2.

1. add touch function, struct declare in SDL_syswm_c.h

#if WINVER < 0x0601

#ifndef WM_TOCUH
#define WM_TOUCH 0x0240
#endif

/* Touch input definitions */
#define TWF_FINETOUCH 1
#define TWF_WANTPALM 2

#define TOUCHEVENTF_MOVE 0x0001
#define TOUCHEVENTF_DOWN 0x0002
#define TOUCHEVENTF_UP 0x0004

DECLARE_HANDLE(HTOUCHINPUT);

typedef struct _TOUCHINPUT {
LONG x;
LONG y;
HANDLE hSource;
DWORD dwID;
DWORD dwFlags;
DWORD dwMask;
DWORD dwTime;
ULONG_PTR dwExtraInfo;
DWORD cxContact;
DWORD cyContact;
} TOUCHINPUT, *PTOUCHINPUT;

extern BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
extern BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int );
extern BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG );

#endif /* WINVER < 0x0601 */

2. in SDL_systemevents.c add function pointers

#include "SDL_loadso.h"
#if WINVER < 0x0601

BOOL (WINAPI *CloseTouchInputHandle)( HTOUCHINPUT );
BOOL (WINAPI *GetTouchInputInfo)( HTOUCHINPUT, UINT, PTOUCHINPUT, int );
BOOL (WINAPI *RegisterTouchWindow)( HWND, ULONG );

#endif /* WINVER < 0x0601 */


3. in SDL_systemevents.c add code to int SDL_RegisterApp(char *name, Uint32 style, void *hInst)

#ifdef WM_MOUSELEAVE
/* Get the version of TrackMouseEvent() we use */
_TrackMouseEvent = NULL;
handle = GetModuleHandle("USER32.DLL");
if ( handle ) {
_TrackMouseEvent = (BOOL (WINAPI *)(TRACKMOUSEEVENT *))GetProcAddress(handle, "TrackMouseEvent");
}
if ( _TrackMouseEvent == NULL ) {
_TrackMouseEvent = WIN_TrackMouseEvent;
}
#endif /* WM_MOUSELEAVE */

#ifdef WM_TOUCH
GetTouchInputInfo = NULL;
CloseTouchInputHandle = NULL;
RegisterTouchWindow = NULL;
handle = GetModuleHandle("USER32.DLL");
if ( handle ) {
GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) GetProcAddress(handle, "GetTouchInputInfo" );
CloseTouchInputHandle =(BOOL (WINAPI *)( HTOUCHINPUT )) GetProcAddress(handle, "CloseTouchInputHandle" );
RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) GetProcAddress(handle, "RegisterTouchWindow" );
}
#endif


#ifndef NO_GETKEYBOARDSTATE
/* Initialise variables for SDL_ToUnicode() */
codepage = GetCodePage();
SDL_ToUnicode = Is9xME() ? ToUnicode9xME : ToUnicode;
#endif

4.in SDL_systemevents.c add code to
LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)

#ifdef WM_TOUCH
case WM_TOUCH:
{
UINT i, num_inputs = LOWORD(wParam);
//you can copy codes from SDL 1.3. but it is not necessary if you just use mouse event
return 0;
}
break;
#endif

5. in SDL_dx5events.c & SDL_dibvideo.c add code
#include "../wincommon/SDL_syswm_c.h"

6. the most important step, let Win7 OS know your ap accept touch message
in SDL_dx5events.c & SDL_dibevents.c add code to
int DX5_CreateWindow(_THIS) & int DIB_CreateWindow(_THIS)

WIN_FlushMessageQueue();

#ifdef WM_TOUCH
/* Enable multi-touch */
if (RegisterTouchWindow) {
RegisterTouchWindow(SDL_Window, (TWF_FINETOUCH|TWF_WANTPALM));
}
#endif


That is all I done.