About Monkey 2 › Forums › Monkey 2 Programming Help › Windows SendInput function
This topic contains 7 replies, has 3 voices, and was last updated by
Hezkore
1 year, 11 months ago.
-
AuthorPosts
-
May 5, 2017 at 1:19 am #8109
I’m working on a front-end for my arcade machine.
I need to translate my custom made gamepad into mouse movements.
I’m trying to figure out how Window’s SendInput function works, but I’m really confused..Here’s the MSDN link to SendInput.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspxAny help?
May 5, 2017 at 5:10 am #8110Can’t you just use MX2’s built-in event handling mechanisms to generate mouse movement events? Eg:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051[crayon-5cba87dbd6163865739531 inline="true" ]#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawText( "Press space...",Width/2,Height/2,.5,.5 )EndMethod OnKeyEvent(event:KeyEvent) OverrideIf event.Type = EventType.KeyRepeatIf event.Key = Key.SpacePrint "Spacebar pressed."Local loc:Vec2iLocal wheel:Vec2iLocal modi:ModifierLocal clicks := 0Local button := MouseButton.LeftSendMouseEvent(New MouseEvent(EventType.MouseMove, Self, loc, button, wheel, modi, clicks))EndifEndifEndMethod OnMouseEvent(event:MouseEvent) OverrideIf event.Type = EventType.MouseClick Then Print "CLICK!"If event.Type = EventType.MouseMovePrint "Mouse moved."EndifEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndMay 5, 2017 at 2:39 pm #8115Hmm, my mouse doesn’t move when I run that code.
But it does print “Spacebar pressed. Mouse moved.”.
I need to actually move the mouse pointer around on the screen.
Triggering the mouse event in M2 sadly isn’t enough.My arcade machine doesn’t have a mouse, just a gamepad I’ve built myself.
Sometimes I do need a mouse though, so I figured I’d code a “mouse mode” or something, where I can control the mouse via the gamepad itself.May 6, 2017 at 12:43 am #8116* Hide the “actual” mouse cursor. Draw a “sprite” mouse cursor instead.
* Read your gamepad input coordinates.
* Translate the coordinates to a screen location vector.
* Draw the mouse cursor sprite at the vector.
* Trigger an EventType.MouseMove event, including the vector.
* Handle the event in the OnMouseEvent method.Easy peasy?!
Or I still misunderstand your objectives… Forgive me if that’s the case.
May 6, 2017 at 12:54 am #8118I need to click Windows buttons, or drag desktop icons, or click Windows text fields, browse the web etc.
The mouse isn’t for my stuff, I just need to control it from my code to interact with lots of other applications.May 6, 2017 at 1:52 am #8119Ah, I see. Then yes, you’ll need something lower level, probably coded in C/C++. Good luck.
May 6, 2017 at 6:57 am #8121Directly with SDL function : SDL_WarpMouseGlobal:Void( x:Int, y:Int )
Remarks : This function generates a mouse motion event. A failure of this function usually means that it is unsupported by a platform.May 6, 2017 at 4:43 pm #8127SDL_WarpMouseGlobal actually works for Windows stuff.
Sadly, it doesn’t seem to register in any other apps.
But it’s something at least!
Big thanks. -
AuthorPosts
You must be logged in to reply to this topic.