Hello. I am working on using Direct Input for my mouse instead of windows, and am running into a problem. I have looked at about 100 tutorials, and they all have things set up the same way. I am guessing the problem is that I am overlooking something, or I am not using the proper header. Anyways, the problem that is occuring is when I get the mouse coordinates, they are not right. So, for example, if the cursor is at 64, 64 : it returns 78, 96 as its coords. Here is my code - what i am showing you is the includes I am using, the mouse initialization, and inside the main where I look for the mouse coords. let me know if you need more information, please.
Includes:
Globals:Code:#pragma once #define WIN32_LEAN_AND_MEAN #define INITGUID #include <windows.h> #include <windowsx.h> #include <mmsystem.h> #include <iostream> #include <conio.h> #include <stdlib.h> #include <malloc.h> #include <memory.h> #include <string.h> #include <stdarg.h> #include <stdio.h> #include <math.h> #include <objbase.h> #include <io.h> #include <fcntl.h> using namespace std; #include <ddraw.h> #pragma comment(lib, "ddraw.lib") #include <dinput.h> #pragma comment (lib, "dinput8.lib") #pragma comment(lib, "dxguid.lib")
Initialization:Code:LPDIRECTINPUT8 lpdi = NULL; LPDIRECTINPUTDEVICE8 lpdikey = NULL; LPDIRECTINPUTDEVICE8 lpdimouse = NULL; LPDIRECTINPUTDEVICE8 lpdijoy = NULL; UCHAR keyboard_state[256]; DIMOUSESTATE mouse_state; DIJOYSTATE joy_state; int mouse_x, mouse_y;
Main:Code:if(FAILED(DirectInput8Create(hinstance_app,DIRECTINPUT_VERSION,IID_IDirectInput8, (void **)&lpdi,NULL))) return 0; if(FAILED(lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL))) return 0; if(FAILED(lpdimouse->SetCooperativeLevel(main_window_handle, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))) return 0; if(FAILED(lpdimouse->SetDataFormat(&c_dfDIMouse))) return 0; if(FAILED(lpdimouse->Acquire())) return 0; mouse_x = SCREEN_HEIGHT/2; mouse_y = SCREEN_WIDTH/2; ShowCursor(TRUE);
I appreciate any help you can give.Code:lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state); mouse_x += (mouse_state.lX); mouse_y += (mouse_state.lY);
Thanks,
Khelder



LinkBack URL
About LinkBacks



.