1

Essentially cannot find and answer to this question, or if it is even possible. I have a game I am creating for a class, and it simply looks better when forced full screen and when the zoom is set to a particular size. I was wonder if I could recreate this without the player being necessary to change it themselves.

ALT + ENTER Full screen And CTRL + Scroll wheel zoom

1 Answers1

1

For a literal answer to your question on how to:

  • Send keys to go Fullscreen, and
  • Send a Ctrl+MouseWheel

You want some help from the Win32 interop to send keyboard & mouse messages to your console window.

using System.Runtime.InteropServices;
public class Win32
{
    public const int VK_F11 = 0x7A;
    public const int SW_MAXIMIZE = 3;

    public const uint WM_KEYDOWN = 0x100;
    public const uint WM_MOUSEWHEEL = 0x20A;

    public const uint WHEEL_DELTA = 120;
    public const uint MK_CONTROL = 0x00008 << 16;

    [DllImport("kernel32.dll")]
    public static extern IntPtr GetConsoleWindow();

    [DllImport("user32.dll")]
    public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}

As reference the magic numbers are from:

You could then simply send your keypress and mousewheel like so:

using static Win32;

// Get window handle of the console
var hwnd = GetConsoleWindow();

// Go fullscreen by sending the F11 keydown message.
PostMessage(hwnd, WM_KEYDOWN, (IntPtr)VK_F11, IntPtr.Zero);

// Or maximize the window instead. Your users may not know how to get out of fullscreen...
/// ShowWindow(hwnd, SW_MAXIMIZE);

// Send mouse wheel message.
// MK_CONTROL: Holds the Ctrl key. WHEEL_DELTA: Positive=Up, Negative=Down.
PostMessage(hwnd, WM_MOUSEWHEEL, (IntPtr)(MK_CONTROL | WHEEL_DELTA), IntPtr.Zero);

Alternatively, as @JeremyLakerman mentioned in a comment to your question, you could set the console font to a larger size; which is a lot better, but also a bit more involved than sending Ctrl+MouseWheel.

NPras
  • 3,135
  • 15
  • 29
  • Thank you very much. Exactly what I was looking for! Really do appreciate the explanation with the annotations to referance! – DannyDestroyer Dec 13 '21 at 06:51