Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, 1 invisible), 620 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
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 Offline OP
User
the_mehmaster  Offline 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 smile

Code:
#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 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
you can try sys_malloc and sys_free

Code:
#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;
}




Visit my site: www.masterq32.de
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 Offline OP
User
the_mehmaster  Offline OP
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
Ah, I forgot about that! Thanks smile!

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 grin)

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 Offline OP
User
the_mehmaster  Offline 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 smile)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 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
What's about GetCursorPos?
Code:
function move_mouserel(int x,int y)
{
    LPPOINT p;
    GetCursorPos(&p);
    SetCursorPos(p.x + x,p.y + y);
}




Visit my site: www.masterq32.de
Re: New, delete, and windows.h [Re: MasterQ32] #350276
12/15/10 03:32
12/15/10 03:32
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline OP
User
the_mehmaster  Offline OP
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
Thanks, but that's not really what I need..

The thing is, I need the function to not just effect desktop apps, but also full-screen games and such too. The only way I have managed to achieve that as yet is through 'SendInput'.

(I did try your code though BTW -- the 'LPPOINT' needs to only be a 'POINT', and it won't work in full-screen apps)

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 Offline OP
User
the_mehmaster  Offline 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
Code:
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 Offline OP
User
the_mehmaster  Offline OP
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
Okay so I have now added
Code:
API(SendInput,user32)



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 Offline OP
User
the_mehmaster  Offline 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:


Code:
#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 wink!!

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 Offline
Serious User
gri  Offline
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)
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1