private void ApplyCurrentScheme(CURSOR_ICON_SCHEME prevScheme, CURSOR_ICON_SCHEME newScheme) { List <int> indicesToChange = new List <int>(); for (int i = 0; i < mouseSchemeStrings.Length; i++) { if (!schemeStringsList[(int)prevScheme][i].Equals(schemeStringsList[(int)newScheme][i])) { indicesToChange.Add(i); } } using (RegistryKey regKey = Registry.CurrentUser.CreateSubKey(@"Control Panel\Cursors", RegistryKeyPermissionCheck.ReadWriteSubTree)) { //if we couldn't open the registry, tell the user and exit if (regKey == null) { Logger.WriteError("Unable to get write permissions to Current User\\Control Panel\\Cursors"); return; } //Show message box to user if icon cannot be found. if (!File.Exists(hcFileStringBaseName + "Arrow.cur")) { Logger.WriteError("Unable to find " + hcFileStringBaseName + "Arrow.cur"); } foreach (int i in indicesToChange) { //Check if we should use hidden cursor here if (schemeStringsList[(int)newScheme][i].Length > 0) { string executingDirectory = Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); string hiddenCursorFullPath = executingDirectory + "\\" + hcFileStringBaseName + pathKeys[i] + ".cur"; //the filename is named accordingly regKey.SetValue(pathKeys[i], hiddenCursorFullPath, RegistryValueKind.String); } else //we want to set back to regular mouse scheme { regKey.SetValue(pathKeys[i], mouseSchemeStrings[i], RegistryValueKind.String); } } } //tell windows we changed the cursor so it gets updated User32.SystemParametersInfo(User32.SPI_SETCURSORS, 0, IntPtr.Zero, 0); }
public void SetCursorScheme(CURSOR_ICON_SCHEME newScheme) { if (newScheme == currentScheme) { //Already set return; } //Do not change scheme from MOUSE to EYEGAZE_ZOOM, as not a valid transition if (currentScheme == CURSOR_ICON_SCHEME.MOUSE && newScheme == CURSOR_ICON_SCHEME.EYEGAZE_ZOOM) { return; } Logger.WriteVar(nameof(currentScheme), currentScheme); Logger.WriteVar(nameof(newScheme), newScheme); ApplyCurrentScheme(currentScheme, newScheme); currentScheme = newScheme; }