Turn numlock on at start

I’ve tried looking through previous answers, but can’t find anything that quite fits the bill.

Basically, all I want is a script in void Start() just to turn numlock on. It doesn’t matter if it’s pressed, or if it was on in the first place, just need to make certain it is on at the start. I’m sure there must be a relatively simple code to do this. Just to note, I am using C#.

Cheers in advance,

Pete

Check this out:

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class SpecialKeyController : MonoBehaviour {

	// Use this for initialization
	void Start () {
	    SetNumLock(true);
	}
	

    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
    private static extern short GetKeyState(int keyCode);

    [DllImport("user32.dll")]
    private static extern int GetKeyboardState(byte[] lpKeyState);

    [DllImport("user32.dll", EntryPoint = "keybd_event")]
    private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);

    private const byte VK_NUMLOCK = 0x90;
    private const uint KEYEVENTF_EXTENDEDKEY = 1;
    private const int KEYEVENTF_KEYUP = 0x2;
    private const int KEYEVENTF_KEYDOWN = 0x0;

    public bool GetNumLock()
    {
        return (((ushort)GetKeyState(0x90)) & 0xffff) != 0;
    }

    public void SetNumLock(bool bState)
    {
        if (GetNumLock() != bState)
        {
            keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYDOWN, 0);
            keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); 
            
        }
    }
}

I would recommend starting here for information on this topic. Keyboard manipulation would be something the OS (Windows, in the case of the link) would handle, rather than a game engine. I don’t know what may or may not be usable in Unity, but that’s probably a good place to start.

Edit: Since the links from that site weren’t great, here’s another reference to “keybd_event”.