1 registered members (AndrewAMD),
1,248
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
New, delete, and windows.h [RESOLVED *yes!*]
#349894
12/12/10 00:08
12/12/10 00:08
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
Hey there, The following code works and is compiling properly in VS 2010 -- But my problem is that I would like to get it working in lite-c... I'm not really sure where to start though, as lite-c does not support or have a lot of what I am using.. I don't think lite-c has the 'new' or 'delete' operators (Which I am using inefficiently, but I need them none the less). Also, many of the structs are not defined in windows.h.. along with the the integral function 'SendInput'.. How would I go about this task? any help is greatly appreciated
#include <windows.h>
void mouseMove(int dx, int dy)
{
INPUT* input = new INPUT;
input->type = INPUT_MOUSE;
input->mi.dx = dx;
input->mi.dy = dy;
input->mi.mouseData = 0;
input->mi.dwFlags = MOUSEEVENTF_MOVE;
input->mi.time = 0;
input->mi.dwExtraInfo = 0;
SendInput(1, input, sizeof(INPUT));
delete input;
}
int main(int argc, _TCHAR* argv[])
{
while(1)
{
mouseMove(4,0);
mouseMove(0,4);
mouseMove(-4,0);
mouseMove(0,-4);
}
return 0;
}
Some links: SendInput A forum post (3rd last post on that page) Thanks in advance...
Last edited by the_mehmaster; 12/15/10 04:39.
|
|
|
Re: New, delete, and windows.h
[Re: the_mehmaster]
#349896
12/12/10 00:12
12/12/10 00:12
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
you can try sys_malloc and sys_free
#include <windows.h>
void mouseMove(int dx, int dy)
{
INPUT* input = sys_malloc(sizeof(INPUT));
input->type = INPUT_MOUSE;
input->mi.dx = dx;
input->mi.dy = dy;
input->mi.mouseData = 0;
input->mi.dwFlags = MOUSEEVENTF_MOVE;
input->mi.time = 0;
input->mi.dwExtraInfo = 0;
SendInput(1, input, sizeof(INPUT));
sys_free(input);
}
void main()
{
while(1)
{
mouseMove(4,0);
mouseMove(0,4);
mouseMove(-4,0);
mouseMove(0,-4);
}
return;
}
|
|
|
Re: New, delete, and windows.h
[Re: MasterQ32]
#349899
12/12/10 00:20
12/12/10 00:20
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
Ah, I forgot about that! Thanks ! That solves half the problem.. The 'INPUT' struct and most of the members it contains are not in the default 'windows.h' though.. I went around copy-pasting all the bits from 'windows.h' that I needed.. But that didn't work very well (not that I expected it too, though ) How do you reckon I would go about gathering the pieces of 'windows.h' that I need?
|
|
|
Re: New, delete, and windows.h
[Re: the_mehmaster]
#349906
12/12/10 07:18
12/12/10 07:18
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
Normally I would use SetCursorPos -- Because that is fully supported within lite-c But that function does not work for me as it only works in some applications, and also I need relative as apposed to absolute coordinate input (although that part could be accomplished in code quite easily) Does anyone else know how to do this? Maybe there is an easier way... EDIT: Well in case anyone wants to know.. I'm using EvilSOB's fantastic serial library (and some more code that he helped me [rather -- he wrote for me XD] write for the IMU )to communicate to an external IMU for accelerometer + gyro data and such.. The reason I am doing this in lite-c is because it would take a while to port over to c++... I want to make an accelerometer-gyro based headtracking thing for use in both acknex, and other games that I have.
Last edited by the_mehmaster; 12/12/10 07:43.
|
|
|
Re: New, delete, and windows.h
[Re: the_mehmaster]
#350206
12/14/10 15:42
12/14/10 15:42
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
What's about GetCursorPos?
function move_mouserel(int x,int y)
{
LPPOINT p;
GetCursorPos(&p);
SetCursorPos(p.x + x,p.y + y);
}
|
|
|
Re: New, delete, and windows.h
[Re: the_mehmaster]
#350279
12/15/10 04:20
12/15/10 04:20
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
Hmm.. I looked in acknex's windows.h, and look what I found, around line 6945
long WINAPI VkKeyScan(long ch);
long WINAPI VkKeyScanEx(long ch,long dwhkl);
VOID WINAPI keybd_event(long bVk,long bScan,long dwFlags,long dwExtraInfo);
VOID WINAPI mouse_event(long dwFlags,long dx,long dy,long dwData,long dwExtraInfo);
//long WINAPI SendInput(long cInputs,long pInputs,long cbSize);
long WINAPI GetLastInputInfo(long plii);
long WINAPI MapVirtualKey(long uCode,long uMapType);
long WINAPI MapVirtualKeyEx(long uCode,long uMapType,long dwhkl);
long WINAPI GetInputState(long);
long WINAPI GetQueueStatus(long flags);
long WINAPI GetCapture(long);
It's already there! -- But it has been commented out for some reason. None of the dependencies for it are there though, as I tried un-commenting it and calling it.. says I'm calling an 'empty prototype' Any ideas?
|
|
|
Re: New, delete, and windows.h
[Re: the_mehmaster]
#350280
12/15/10 04:24
12/15/10 04:24
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
Okay so I have now added And something real strange is happening.. nothing! .. Program finishes compiling then the whole computer freezes
|
|
|
Re: New, delete, and windows.h
[Re: the_mehmaster]
#350282
12/15/10 04:38
12/15/10 04:38
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
GREAT SCOTT I think I have it!! Program now does what I want it to .. Yay!! For anyone else who wants to achieve a similar feat: First you must go into acknex's windows.h, and uncomment 'long WINAPI SendInput(long cInputs,long pInputs,long cbSize);' Also, 'API(SendInput,user32)' needs to be added there, and then this code will work:
#include <acknex.h>
#include <default.c>
#include <windows.h>
typedef unsigned long ULONG_PTR;
typedef struct tagMOUSEINPUT {
LONG dx;
LONG dy;
DWORD mouseData;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} MOUSEINPUT;
#define INPUT_MOUSE 0
typedef struct tagINPUT {
DWORD type;
MOUSEINPUT mi;
} INPUT;
void mouseMove(int dx, int dy)
{
INPUT* input = sys_malloc(sizeof(INPUT));
input.type = INPUT_MOUSE;
input.mi.dx = dx;
input.mi.dy = dy;
input.mi.mouseData = 0;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
input.mi.time = 0;
input.mi.dwExtraInfo = 0;
SendInput(1, input, sizeof(INPUT));
sys_free(input);
}
void main()
{
level_load("");
while(1)
{
mouseMove(4,0);
wait(1);
mouseMove(0,4);
wait(1);
mouseMove(-4,0);
wait(1);
mouseMove(0,-4);
wait(1);
}
}
Yes!!! Thanks Richi007 for the help !!
|
|
|
Re: New, delete, and windows.h
[Re: the_mehmaster]
#350285
12/15/10 06:40
12/15/10 06:40
|
Joined: Dec 2003
Posts: 1,225 germany
gri
Serious User
|
Serious User
Joined: Dec 2003
Posts: 1,225
germany
|
Thanx for sharing your solution
"Make a great game or kill it early" (Bruce Shelley, Ensemble Studios)
|
|
|
|