Recent

Author Topic: SendInput  (Read 14252 times)

penpen

  • New Member
  • *
  • Posts: 23
SendInput
« on: September 12, 2012, 01:59:52 am »
Hey.
I'm wanting to use SendInput with lazarus and found it in the windows.h (redef.inc).
It was commented so I uncommented It.

To use it you need a variable of type TInput though.

But I cant find the definition for this type. Where is the Tinput var declared ? and how does that look ?

Hope you can help me D:

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: SendInput
« Reply #1 on: September 12, 2012, 08:25:14 am »
What do you need TInput for? There is already a component MouseAndKeyInput in Lazarus, without having to go modify source code, and crossplatform way...

penpen

  • New Member
  • *
  • Posts: 23
Re: SendInput
« Reply #2 on: September 12, 2012, 11:18:44 am »
I'm wanting to send Clicks without moving the mouse.

And I tried about everything but the window that is to receive the clicks only accepts the clicks when the mouse is over the target. So I've red about SendInput and thought I'd give it a shot.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: SendInput
« Reply #3 on: September 12, 2012, 01:21:07 pm »
You would do better to post your code so others can see how you "send clicks" and comment on it.
Calling Form1.Click in code works as expected here, whether the mouse cursor happens to be above Form1 or not.

penpen

  • New Member
  • *
  • Posts: 23
Re: SendInput
« Reply #4 on: September 12, 2012, 01:58:23 pm »
Okay here are my tries:
        v:= MakeLParam(127,116); 
         SendMessage(pokerhwnd, WM_RBUTTONDOWN, MK_RBUTTON, v);
         SendMessage(pokerhwnd, WM_RBUTTONUP,MK_RBUTTON, v);         

         POSTMessage(pokerhwnd, WM_RBUTTONDOWN, MK_RBUTTON, v);
         POSTMessage(pokerhwnd, WM_RBUTTONUP,MK_RBUTTON, v);     

   mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

All the above functions work in windows like Firefox, but only mouse_event works in the window I'm targeting... But... I dont want it to really move the mouse, just send the clicks.



User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: SendInput
« Reply #5 on: September 12, 2012, 06:44:53 pm »
Well, like i said the MouseAndKeyInput above can do things like that. There are for example procedures:
Code: [Select]
procedure Click(Button: TMouseButton; Shift: TShiftState); // This seems like what you need
procedure Click(Button: TMouseButton; Shift: TShiftState; ScreenX, ScreenY: Integer);

penpen

  • New Member
  • *
  • Posts: 23
Re: SendInput
« Reply #6 on: September 12, 2012, 07:58:12 pm »
I dont want to move the mouse cursor though.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: SendInput
« Reply #7 on: September 12, 2012, 08:16:58 pm »
Quote
I dont want to move the mouse cursor though.
The first click method does NOT move the cursor, did you even read User137 answer?

penpen

  • New Member
  • *
  • Posts: 23
Re: SendInput
« Reply #8 on: September 12, 2012, 11:56:03 pm »
I Tried that function and it did move the mouse to the target location.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: SendInput
« Reply #9 on: September 13, 2012, 01:19:22 am »
Quote
I Tried that function and it did move the mouse to the target location.
Show us your code, because the source code (winmouseinput.pas) doesn't say so according to MSDN.

penpen

  • New Member
  • *
  • Posts: 23
Re: SendInput
« Reply #10 on: September 13, 2012, 01:22:48 am »
hmmn..

  MouseInput.Click(mbLeft, [], 2078, 698);     

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: SendInput
« Reply #11 on: September 13, 2012, 01:27:57 am »
Quote
MouseInput.Click(mbLeft, [], 2078, 698);
As expected, you're executing the second method, not the first one. Make the main window on focus, get the mouse cursor out of there, and use the first method (without ScreenX and ScreenY parameters).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: SendInput
« Reply #12 on: September 13, 2012, 01:33:09 am »
hmmn..

  MouseInput.Click(mbLeft, [], 2078, 698);     

Code: [Select]
Var
  TempPos:Tpoint;
Begin
  TempPos := Mouse.CursorPos;
  MouseInput.Click(mbLeft, [], 2078, 698);     
  MouseInput.Move([],TempPos.X,TempPos.Y);
end;

That's simple enough?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

penpen

  • New Member
  • *
  • Posts: 23
Re: SendInput
« Reply #13 on: September 13, 2012, 01:49:10 am »
This probably wont work on windows in background though. :(

penpen

  • New Member
  • *
  • Posts: 23
Re: SendInput
« Reply #14 on: September 15, 2012, 03:28:08 pm »
I'm wanting to get back to this again, since its still not solved  :'(

So what can we try to send clicks on a background Window when SendMessage and PostMessage doesnt work ?

 

TinyPortal © 2005-2018