// // 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; /// /// Represents window of nostale client. /// public class NostaleWindow { private const int WM_KEYDOWN = 0x0100; private const int WM_KEYUP = 0x0101; private const int WM_CHAR = 0x0102; /// /// Initializes a new instance of the class. /// /// The handle of the window. public NostaleWindow(IntPtr handle) => Handle = handle; /// /// Gets the window handle. /// public IntPtr Handle { get; } /// /// Changes the title of the window. /// /// The new name of the window. public void Rename(string name) { User32.SetWindowText(Handle, name); } /// /// Bring the window to front. /// public void BringToFront() { User32.SetForegroundWindow(Handle); } /// /// Send the given key to the window. /// /// The id of the key. 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); } }