~ruther/NosSmooth.Local

ref: d27c4708d5acef840a1037762ec70a2b07cb037c NosSmooth.Local/src/Core/NosSmooth.LocalClient/NostaleWindow.cs -rw-r--r-- 1.5 KiB
d27c4708 — Rutherther fix(binding): use correct name in OptionalNotPresentError 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
//  NostaleWindow.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using NosSmooth.LocalClient.Utils;

namespace NosSmooth.LocalClient;

/// <summary>
/// Represents window of nostale client.
/// </summary>
public class NostaleWindow
{
    private const int WM_KEYDOWN = 0x0100;
    private const int WM_KEYUP = 0x0101;
    private const int WM_CHAR = 0x0102;

    /// <summary>
    /// Initializes a new instance of the <see cref="NostaleWindow"/> class.
    /// </summary>
    /// <param name="handle">The handle of the window.</param>
    public NostaleWindow(IntPtr handle) => Handle = handle;

    /// <summary>
    /// Gets the window handle.
    /// </summary>
    public IntPtr Handle { get; }

    /// <summary>
    /// Changes the title of the window.
    /// </summary>
    /// <param name="name">The new name of the window.</param>
    public void Rename(string name)
    {
        User32.SetWindowText(Handle, name);
    }

    /// <summary>
    /// Bring the window to front.
    /// </summary>
    public void BringToFront()
    {
        User32.SetForegroundWindow(Handle);
    }

    /// <summary>
    /// Send the given key to the window.
    /// </summary>
    /// <param name="key">The id of the key.</param>
    public void SendKey(uint key)
    {
        User32.PostMessage(Handle, WM_KEYDOWN, key, 0);
        User32.PostMessage(Handle, WM_CHAR, key, 0);
        User32.PostMessage(Handle, WM_KEYUP, key, 0);
    }
}
Do not follow this link