Results 1 to 9 of 9

Thread: [3.0/LINQ] Simulate user input presicely

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Resolved [3.0/LINQ] Simulate user input presicely

    I have a class that derives from Form that won't be able to get mouse or key input normally. I have outside classes that monitor the mouse and keyboard. I want to be able to send keypresses / mouse events etc. just as if the form had received them its self.

    I've tried things like calling OnMouseDown, OnClick etc. but the problem, as illistrated by these 2 methods is that a child's click / mousedown event won't get raised if appropriate. i.e. i call onmousedown with mouse coordinates that would be over a control on the form, but the event is never raised on the control.

    Anyone know how i can achieve the effect i'm after?
    Last edited by SLH; Oct 19th, 2008 at 10:51 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [3.0/LINQ] Simulate user input presicely

    You should be sending Windows messages to the form, which will cause it to raise its own events. You need to call the SendMessage API. Create a regular form and override its WndProc method. You can then monitor the messages it receives under various circumstances and reproduce them yourself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Simulate user input presicely

    If that works (child controls get the messages/events as appropriate) then that'll be perfect.

    Cheers!
    I'll check that the child control's events get fired as appropriate then i'll mark this thread resolved and give you some lovely lovely rep points.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Simulate user input presicely

    Hmm, i've tried using the send message approach, but it doesn't seem to work as i'd hoped.

    If i send a WM_MOUSEDOWN message to the form's handle the form's OnMouseDown method does get fired, and if i check the mouseeventargs passed into it i know i'm passing the correct lparam and wparam to indicate the mousebutton and cursor position.

    However, even if i click on my usercontrol the onmousedown method is never ran (i checked with a breakpoint).

    Any ideas as to why this could happen?
    If i sent a message using this method to an external applicaion would it behave as i want it to here? i.e. would a child window have its click event called? If not then i'm a bit stuck, if it does behave like that then i'm obviously doing something wrong.

    The way i'm sending the message to my form is by calling its WndProc method with my newly created Message object. (i exposed the WndProc with a helper method that calls it).
    Last edited by SLH; Oct 12th, 2008 at 07:34 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [3.0/LINQ] Simulate user input presicely

    When you were creating your fancy Form class, did you happen to use SetStyle() to alter the handling of mouse events?
    I don't live here any more.

  6. #6

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Simulate user input presicely

    Nope.

    I've just created a test winforms project to test this, and that doesn't work either so i know the problem isn't with my derived classes.

    To test it i created a test form with 2 buttons, one at location 0,0 and another somewhere else. In the 2nd button's click event i send a message to the form that clicks at a location inside the 1st button. However, the 1st button's click event, or mouse down event doesn't get called
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [3.0/LINQ] Simulate user input presicely

    It's been a while since I meddled in this, but wouldn't (0,0) be underneath the form's titlebar? I don't know what x,y coords you used in your message, nor how big your button is.

    Try making the button 100w x 100h at position 0,0 and send the click message to 99,99.
    I don't live here any more.

  8. #8

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Simulate user input presicely

    Good idea, but no luck still.
    I'm starting to think that sending a message to a parent window simply won't send any message or anything to a child window.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  9. #9

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Simulate user input presicely

    Cracked it! The parent window never gets a mousedown message when one of its child windows receives one.
    I got it to work by simply working out what control was clicked then sending the message to that.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width