Question

I have a problem with my tool (www.ljtd.net - no ad, just if someone want to test out the problem) for League of Legends. Let's say it works properly except a little mistake. For the guys who don't know the game. It's a MOBA which is like DotA.

My problem right now is that my tool is an overlay and showing additional information for the game. So when clicking this tool, the click should not effect the game-behaviour (you should stay in the game as if nothing has happenend). That's why I use the SetForegroundWindow which works pretty well. The game is getting back the focus and also driving over the in-game minimap is working. But sometimes clicking my tool has another unusual behaviour. The game still gets the focus. But driving on top of the minimap now behaves as if you are actually holding down the left mouse button there.

So my question is why it sometimes work properly with the minimap and in like 50% it does not. Many other users also have the same issue. So I think it's not the game or the Windows configuration. Is there some way to give a better focus to a game like League of Legends? Here is some of the code for the SetForegroundWindow:

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As IntPtr) As Int32
Public tHandle As Long = FindWindow(vbNullString, "League of Legends (TM) Client")

Public Sub SetForeground()
    SetForegroundWindow(tHandle)
End Sub

This small snippet actually gives the focus to the game. If you are interested in the project or want to get a closer look. Have a look here: Complete Source code

Thanks for any ideas you have =)

Another approch I had

Just to show that I already searched for another ways. Here is one that came with the same result. Always the minimap is a bit buggy:

Public Structure PointAPI
    Public x As Integer
    Public y As Integer
End Structure
Module Module_SetMouseclick
    Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
    Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
    Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As PointAPI) As Boolean
    Private Const MOUSEEVENTF_LEFTDOWN = &H2
    Const MOUSEEVENTF_LEFTUP As Integer = &H4
    Public x, y As Integer
    Public Sub Position_Click(ByVal x As Integer, ByVal y As Integer, ByVal click As Boolean)
        SetCursorPos(x, y)
        If click Then
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 1)
        Else
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 1)
        End If
    End Sub
End Module

And somewhere else I access this function with

Module_SetMouseclick.Position_Click(500, 500, True)
Module_SetMouseclick.Position_Click(500, 500, False)

What the does is that there will be a left mouse click at 500, 500 pixels. And as I said the same behaviour like just giving the foreground with SetForegroundWindow.

Was it helpful?

Solution

Solution is:

SetBackupCursorPos()
Position_Click(Module_Generate.ScreenWidth / 2, Module_Generate.ScreenHeight / 2, True)
Threading.Thread.Sleep(100)
Position_Click(x, y, False)

With the delay it now works. Below 100 ms it still buggs with the 100 everything seems fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top