(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
06-01-24 09:30 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - c++ - repeating mouse btn
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
HyperHacker
Posts: 678/5072
Make sure bThreadShouldEnd is volatile if you do that, though. Since the loop never actually modifies it, the compiler may optimize it out otherwise.
Vertex
Posts: 2/4
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
KTurbo
Posts: 19/164
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.
HyperHacker
Posts: 670/5072
It has periodic timers, but I don't think it has one-shot.
Cellar Dweller +
Posts: 29/138
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.
KTurbo
Posts: 18/164
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.
HyperHacker
Posts: 651/5072
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.
MisterJones
Posts: 16/125
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.
KTurbo
Posts: 16/164
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? _¬
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.011 seconds; used 352.00 kB (max 400.78 kB)