Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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 (AndrewAMD, dr_panther), 730 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
lorikob361, LucasJoshua, Baklazhan, Hanky27, firatv
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
mouse #290465
09/19/09 10:15
09/19/09 10:15
Joined: Jul 2007
Posts: 959
nl
F
flits Offline OP
User
flits  Offline OP
User
F

Joined: Jul 2007
Posts: 959
nl
is it possible to simulate a mouse click

like when you press space the windows mouse is clicked

thx flits


"empty"
Re: mouse [Re: flits] #290471
09/19/09 11:07
09/19/09 11:07
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
The Win32 function "SendInput" is what you want...

Here is how to simulate a left-click...
Code:
void LeftClick()
{  
  INPUT    Input={0};
  // left down 
  Input.type      = INPUT_MOUSE;
  Input.mi.dwFlags  = MOUSEEVENTF_LEFTDOWN;
  SendInput(1,&Input,sizeof(INPUT));
}


So then just call LeftClick() and a left-click will be simulated. This only allows you to click on the current mouse position. If you want to first move the mouse use this function...
Code:
void MouseMove(int x, int y )
{  
  double fScreenWidth    = ::GetSystemMetrics( SM_CXSCREEN )-1; 
  double fScreenHeight  = ::GetSystemMetrics( SM_CYSCREEN )-1; 
  double fx = x*(65535.0f/fScreenWidth);
  double fy = y*(65535.0f/fScreenHeight);
  INPUT  Input={0};
  Input.type      = INPUT_MOUSE;
  Input.mi.dwFlags  = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
  Input.mi.dx = fx;
  Input.mi.dy = fy;
  SendInput(1,&Input,sizeof(INPUT));
}




Last edited by DJBMASTER; 09/20/09 07:43.
Re: mouse [Re: DJBMASTER] #290490
09/19/09 13:42
09/19/09 13:42
Joined: Jul 2007
Posts: 959
nl
F
flits Offline OP
User
flits  Offline OP
User
F

Joined: Jul 2007
Posts: 959
nl
thx but dont get it to work
do i need to include some header ore structs

i am not so good with the win32 comments but including windows.h didnt work

Last edited by flits; 09/19/09 13:43.

"empty"
Re: mouse [Re: flits] #290575
09/20/09 07:40
09/20/09 07:40
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Hi, sorry for the late reply. I assumed you knew about the structs. This should work now...
Code:
#include <windows.h>

#define MOUSE_INPUT 0x0000
#define MOUSEEVENTF_LEFTDOWN 0x0002

typedef struct
{
    long dx;
    long dy;
    DWORD mouseData;
    DWORD dwFlags;
    DWORD time;
    long dwExtraInfo;
} 
MOUSEINPUT;

typedef struct
{ 
  DWORD type; 
  MOUSEINPUT mi; 
}
INPUT;

int WINAPI SendInput(int nInputs,INPUT* pInputs,int cbSize);
#define PRAGMA_API SendInput;user32!SendInput

//////////////////////////////////////////////////////////////

void LeftClick()
{  
  INPUT Input;
  Input.type      = MOUSE_INPUT;
  Input.mi.dwFlags  = MOUSEEVENTF_LEFTDOWN;
  SendInput(1,&Input,sizeof(INPUT));
}


I havent included the function to move the mouse, because you can do that by changing mouse_pos/pos_cursor.

Last edited by DJBMASTER; 09/20/09 07:41.
Re: mouse [Re: DJBMASTER] #290591
09/20/09 10:07
09/20/09 10:07
Joined: Jul 2007
Posts: 959
nl
F
flits Offline OP
User
flits  Offline OP
User
F

Joined: Jul 2007
Posts: 959
nl
i did know there needed to be some struct but it is always hard to find them on the msdn page

it realy works good

thx flits


"empty"
Re: mouse [Re: flits] #290593
09/20/09 10:09
09/20/09 10:09
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
ahh yeh i agree, msdn is hard to follow sometimes. Anyway glad it works.

Re: mouse [Re: DJBMASTER] #291319
09/24/09 14:48
09/24/09 14:48
Joined: Jul 2007
Posts: 959
nl
F
flits Offline OP
User
flits  Offline OP
User
F

Joined: Jul 2007
Posts: 959
nl
oke next problem is the key mapping

i just want to do somthin like presing awds and more but i gues if i can press one button i can do the rest

this is what i got for now

Code:
#define KEYEVENTF_UNICODE 0x0004
#define KEYEVENTF_SCANCODE 0x0008
#define INPUT_KEYBOARD 0x0001

typedef struct{
    WORD wVk;
    WORD wScan;
    DWORD dwFlags;
    DWORD time;
    long dwExtraInfo;
}KEYBDINPUT;

typedef struct
{ 
  DWORD type; 
  KEYBDINPUT ki; 
}
KEYINPUT;




"empty"
Re: mouse [Re: flits] #291440
09/25/09 10:14
09/25/09 10:14
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
hmm, should be the same as the mouse i would think...
Code:
#define INPUT_KEYBOARD 0x0001
#define KEYEVENTF_SCANCODE 0x0008

typedef struct
{
    WORD wVk;
    WORD wScan;
    DWORD dwFlags;
    DWORD time;
    long dwExtraInfo;
} 
KEYBDINPUT;

typedef struct
{ 
  DWORD type; 
  KEYBDINPUT ki; 
}
INPUT;

int WINAPI SendInput(int nInputs,INPUT* pInputs,int cbSize);
#define PRAGMA_API SendInput;user32!SendInput

///////////////////////////////////////////////////////////////////////

void PressKey (int scan_code)
{
  INPUT Input;
  Input.type  = INPUT_KEYBOARD;
  Input.ki.wScan = scan_code;
  Input.ki.dwFlags =  KEYEVENTF_SCANCODE;
 
  SendInput(1,&Input,sizeof(Input));
}


I don't have time to test this right now, but it looks ok.

Re: mouse [Re: DJBMASTER] #291645
09/27/09 08:17
09/27/09 08:17
Joined: Jul 2007
Posts: 959
nl
F
flits Offline OP
User
flits  Offline OP
User
F

Joined: Jul 2007
Posts: 959
nl
hmmm i tried allot but i cant get it to work


"empty"
Re: mouse [Re: flits] #291653
09/27/09 10:10
09/27/09 10:10
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
hmmm yeh, i can't seem to get it to send a key either. Maybe A7 internally controls the whole keyboard stream and doesnt allow manual input or something. I don't really know what the problem is. Maybe you should post this in "Ask the Developers".

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