(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-17-24 06:49 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - c++ - repeating mouse btn New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
KTurbo

Poppy Bros. Jr


 





Since: 11-19-05
From: Schweden

Last post: 6300 days
Last view: 6298 days
Posted on 01-07-06 09:58 AM Link | Quote
Hi ho, I'm trying come up with a code which makes the [mousedown] command repeat itself over and over until you release the mouse btn, it could be use as a e.g. autoshot in a game. Could anyone give me a hint how to do this? _¬
MisterJones

Tooky








Since: 12-08-05
From: Mexico

Last post: 6387 days
Last view: 6323 days
Posted on 01-07-06 11:57 AM Link | Quote
Originally posted by KTurbo
Hi ho, I'm trying come up with a code which makes the [mousedown] command repeat itself over and over until you release the mouse btn, it could be use as a e.g. autoshot in a game. Could anyone give me a hint how to do this? _¬



On first mousedown even you could set some switch wichih will do something by default, until the mouseup even comes in.
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6298 days
Last view: 6298 days
Posted on 01-07-06 06:38 PM Link | Quote
If you're trying to do this for your own program, then yeah, just act as if you kept recieving it. Maybe use PostMessage() to send another one if no mouseup message has come in yet.

If you want another program to have this behaviour, that's going to be more difficult. You can 'hijack' the message handler in older versions of Windoze, but for some reason in newer versions MS decided you can only do that if the window belongs to your program.
KTurbo

Poppy Bros. Jr


 





Since: 11-19-05
From: Schweden

Last post: 6300 days
Last view: 6298 days
Posted on 01-07-06 07:07 PM Link | Quote
Alright, I'll try that, later. But don't expect me to succeed, I'm new to most things you mentioned.

Edit: Btw if it makes any diffence, I'm using Borland builder.


(edited by KTurbo on 01-07-06 06:09 PM)
Cellar Dweller +

Red Koopa









Since: 11-18-05
From: Arkansas

Last post: 6306 days
Last view: 6297 days
Posted on 01-07-06 10:57 PM Link | Quote
I haven't done much with the Windows API in ages, but may I suggest a timer. I don't remember if Windows provdes one shot, peroidic, or both kinds of timers. It sounds like you need a periodic timer, where you can start it when the mouse button is pressed, perform an action when a timer message is received, and stop it when the button is released. If you can only find a one shot timer, restart it on every timer message.
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6298 days
Last view: 6298 days
Posted on 01-08-06 03:04 AM Link | Quote
It has periodic timers, but I don't think it has one-shot.
KTurbo

Poppy Bros. Jr


 





Since: 11-19-05
From: Schweden

Last post: 6300 days
Last view: 6298 days
Posted on 01-08-06 05:25 AM Link | Quote
I tried with a timer, I just didn't remember how I should do to execute it. If it would work I could just make it do something every 20 ms while the mouse btn is pressed, but I can't mix bool with void.
Vertex
Newcomer


 





Since: 01-08-06
From: Philippines

Last post: 6703 days
Last view: 6703 days
Posted on 01-08-06 10:41 PM Link | Quote
The problem is, if you're going to check the mouse is down, and you need to simulate mouse clicking (mousedown + mouseup) then you're not going to be able to tell when the actual mouse is down, because you'll be setting the mouse button state to 'up' every 20ms.. it would work if you just simulated mousedown over and over though, so I'll demonstrate that.

Another idea would be to get the hWnd of the game's input thread window, and just PostMessage to it every 20ms while the mouse is down. Due to the way Timers work in Win32 it might just be easier to create a thread with a consitent loop.

void MouseCheckThread(void)
{
INPUT i;

i.dwType = INPUT_MOUSE
i.mi.dx = i.mi.dy = 0;
i.mi.mouseData = 0;
i.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
i.mi.time = 0;
i.mi.dwExtraInfo = 0;

while (!bThreadShouldEnd)
{
if (GetKeyState(VK_LBUTTON) & 0x8000)
SendInput(1, &i, sizeof(i));
Sleep(20); // just so it doesn't eat up your processor time
}
}

That will check every 20ms if the left mouse button is down, and if it is, send an input message to the system that the mousebutton is being clicked again.

If you get the window handle, you can do this:

void MouseCheckThread(HWND hWndInputThread)
{
while (!bThreadShouldEnd)
{
if (GetKeyState(VK_LBUTTON) & 0x8000)
PostMessage(hWndInputThread, WM_LBUTTONDOWN, MK_LBUTTON, (LPARAM)0x00000000);
Sleep(20); // just so it doesn't eat up your processor time
}
}

Hopefully this will help you. Sorry about the bad formatting


(edited by Vertex on 01-08-06 09:43 PM)
(edited by Vertex on 01-08-06 09:45 PM)
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6298 days
Last view: 6298 days
Posted on 01-08-06 11:47 PM Link | Quote
Make sure bThreadShouldEnd is volatile if you do that, though. Since the loop never actually modifies it, the compiler may optimize it out otherwise.
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - c++ - repeating mouse btn |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.012 seconds; used 389.45 kB (max 482.40 kB)