Use C # to create a "QQ battle platform room dashboard"

Source: Internet
Author: User

1. What is "QQ vs. platform room dashboard "?

Anyone who likes to play games on "QQ vs. platform" or "haofang vs. platform" knows. Generally, most of the rooms on the platform are full. If you want to find a room, it takes a long time to "squeeze" the room. If it is a holiday or evening, it will take more time to "squeeze" the room, such:

For "QQ combat platform", if the room is full, but abnormal, two prompts will pop up! In normal times, you just press the "Enter key" or "Space key" to close these two annoying pop-up windows, and then click the room with the mouse. if the room is still inaccessible, we can only repeat the previous cycle ...... One or two times are not a problem. Five or ten times may not be a problem. But if you cannot squeeze in more than a dozen or even hundreds of times, you can press it! Of course, if you like hand abuse, you can also say -_-#

I don't like hand abuse, so when I encounter N times or cannot squeeze in, I wonder why I don't write a tool to replace my hand, I used a tool to "squeeze" my room automatically. Could you help me with the two annoying Prompt Windows? As a result, the "QQ battle platform room dashboard" in this article was born like this (How many hands can be liberated, everyone applauded ......)

2. How to squeeze a room "?

As mentioned above, the "squeeze room" means to help us automatically "squeeze" the room, but how does it help us "squeeze? After all, it is a machine, not a human. It will not automatically "squeeze" us as soon as we see the room, unless we have customized a set of rules (or commands) for it ). A machine is a machine. If there is a rule, it will do things. If there is no rule, it will do things. Then it is a "person" (Intelligent Robot ?) .

How should we customize this rule? Let's first take a look at our usual process of entering the room, such:

Well, according to the above process, we will customize the following rules for the "dashboard:

1) Click the room.

2) Determine whether the room is in. If the room is not in, close the two annoying Prompt Windows that show the room is full and return to step 2.

3) If you have entered the room, stop the "squeeze" operation.

3. implement automatic room squeeze.

The implementation here is to use the code to implement the three rules customized above.

1. Click the room:

Here we are simple, justSimulate the mouse and click the current room. Speaking of this, maybe a friend who has developed a WINDOWS application has figured out which API functions to use to simulate, right! The following APIs can be used together to simulate mouse clicks.

1) GetCursorPos: obtains the current location of the mouse.

The prototype is as follows:

[DllImport ("user32.dll")]
Internal static extern bool GetCursorPos (out Point lpPoint );

This function returns the coordinates of the current mouse.

2) mouse_event: simulation of mouse events

The prototype is as follows:

[DllImport ("user32.dll", EntryPoint = "mouse_event")]
Public static extern void mouse_event (
Int dwFlags,
Int dx,
Int dy,
Int dwData,
Int dwExtraInfo
);

This function is defined using different dwFlags parameters to simulate different mouse events, such as pressing the left mouse button or popping up events.

Combined with the above two API functions, we can achieve the effect of automatically clicking the room where the mouse is located ", similar to the following code:

Point point;

If (Win32API. GetCursorPos (out point )){

// MouseAPI is a simple encapsulation of the mouse_event API function.

MouseAPI. SendMouseEvent (MouseAPI. MouseEvents. LeftButtonDown | MouseAPI. MouseEvents. LeftButtonUp, point, true );

}

But the above code is very "mechanical", that is, no matter whether the current mouse is in the room or not, it will automatically "click" once! This is not user-friendly, so let's make another improvement. When we click it, we will first judge whether the current mouse stays in the room of the combat platform, but unfortunately the room of the QQ combat platform is not a standard WINDOWS Control, therefore, the room data cannot be obtained. In the end, we have to simply judge whether the window with the mouse is the Hall of the QQ combat platform, because the hall is a WINDOWS window control that can be obtained, the hall data obtained using Spy ++ is as follows:

That is to say, we can determine whether the type of the window where the mouse stays belongs to "Afx: 400000: 3". If so, it indicates that the mouse stays in the game hall of the QQ game platform, you can click the room (note: the location of the stay here is not necessarily on the room, but this does not affect usage, so I did not handle it)

The following APIs are required:

3) WindowFromPoint: obtains the window where a coordinate position is located.

The prototype is as follows:

[DllImport ("user32.dll")]
Internal static extern IntPtr WindowFromPoint (Point );

4) GetClassName: Get the type name of a window

The definition is as follows:

[DllImport ("user32.dll", CharSet = CharSet. Unicode, SetLastError = true)]
Internal static extern int GetClassName (IntPtr hWnd, StringBuilder buf, int nMaxCount );

After adding the above condition judgment, the code above is improved as follows:

if (Win32API.GetCursorPos(out point)){    hwnd = Win32API.WindowFromPoint(point);    if (hwnd != IntPtr.Zero)    {        string className = Win32API.GetWindowClassName(hwnd);        if (className.Equals("Afx:400000:3"))        {            MouseAPI.SendMouseEvent(MouseAPI.MouseEvents.LeftButtonDown | MouseAPI.MouseEvents.LeftButtonUp, point, true);        }    }}
In this way, the "click the room" step is perfect. When the mouse is not in the room (not in the game lobby), the mouse will not be messy, this makes it easy to switch the window at any time when the room is crowded.

2. Check whether you have entered the room. If you have not entered the room, close the two annoying Prompt Windows that show the room full.

 1) Determine whether the room is in: Determine whether to stop the mouse with the above step

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.