/// <summary> /// Rotates the screen from its current location by 90 degrees either clockwise or anti-clockwise. /// </summary> /// <param name="clockwise">Set to true to rotate the screen 90 degrees clockwise from its current location, or false to rotate it anti-clockwise.</param> public static void RotateScreen(bool clockwise) { DisplaySettings set = DisplayManager.GetCurrentSettings(); int tmp = set.Height; set.Height = set.Width; set.Width = tmp; if (clockwise) { set.Orientation++; } else { set.Orientation--; } if (set.Orientation < Orientation.Default) { set.Orientation = Orientation.Clockwise270; } else if (set.Orientation > Orientation.Clockwise270) { set.Orientation = Orientation.Default; } SetDisplaySettings(set); }
public GregwareCustomizations(bool isFullscreenGregware, bool isScrollGregware, bool isGentool, int width, int height, TaskScheduler uiScheduler) { _isFullscreenGregware = isFullscreenGregware; _isScrollGregware = isScrollGregware; _isGentool = isGentool; _width = width; _height = height; _uiScheduler = uiScheduler; _isGentool = isGentool; _originalDisplaySettings = DisplayManager.GetCurrentSettings(); }
/// <summary> /// Changes the current display settings with the new settings provided. May throw InvalidOperationException if failed. Check the exception message for more details. /// </summary> /// <param name="set">The new settings.</param> /// <remarks> /// Internally calls ChangeDisplaySettings() native function. /// </remarks> public static void SetDisplaySettings(DisplaySettings set) { SafeNativeMethods.DEVMODE mode = GetDeviceMode(); mode.dmPelsWidth = (uint)set.Width; mode.dmPelsHeight = (uint)set.Height; mode.dmDisplayOrientation = (uint)set.Orientation; mode.dmBitsPerPel = (uint)set.BitCount; mode.dmDisplayFrequency = (uint)set.Frequency; DisplayChangeResult result = (DisplayChangeResult)SafeNativeMethods.ChangeDisplaySettings(ref mode, 0); string msg = null; switch (result) { case DisplayChangeResult.BadDualView: msg = "The settings change was unsuccessful because system is DualView capable."; break; case DisplayChangeResult.BadParam: msg = "An invalid parameter was passed in. This can include an invalid flag or combination of flags."; break; case DisplayChangeResult.BadFlags: msg = "An invalid set of flags was passed in."; break; case DisplayChangeResult.NotUpdated: msg = "Unable to write settings to the registry."; break; case DisplayChangeResult.BadMode: msg = "The graphics mode is not supported."; break; case DisplayChangeResult.Failed: msg = "The display driver failed the specified graphics mode."; break; case DisplayChangeResult.Restart: msg = "The computer must be restarted in order for the graphics mode to work."; break; } if (msg != null) { throw new InvalidOperationException(msg); } }
public void Activer() { // Initialisation _enabled = true; // Trouver le process Process process = Process.GetProcessesByName("game.dat").FirstOrDefault(); if (process == null) { throw new Exception("Problème d'exécution du jeu, si cette erreur persiste essayer de désactiver les options Gregware (fullscreen et scroll)"); } if (_isFullscreenGregware) { // Changer resolution if (_originalDisplaySettings.Width != _width || _originalDisplaySettings.Height != _height) { DisplaySettings newDs = new DisplaySettings { BitCount = _originalDisplaySettings.BitCount, Frequency = _originalDisplaySettings.Frequency, Index = _originalDisplaySettings.Index, Orientation = _originalDisplaySettings.Orientation, Width = _width, Height = _height }; DisplayManager.SetDisplaySettings(newDs); _resolutionChanged = true; } // Attendre if (_width == 800) { // si width de 800 on ne peut pas différencier splash screen du jeu, on attend 10 secondes bêtement... Thread.Sleep(10000); } else { // sinon on peut différencier, on attend juste ce qu'il faut - 10 sec max Stopwatch sw = new Stopwatch(); sw.Start(); Rect rect = new Rect(); GetWindowRect(process.MainWindowHandle, ref rect); while (rect.Right - rect.Left != _width && sw.Elapsed.Milliseconds < 10000) { Thread.Sleep(100); GetWindowRect(process.MainWindowHandle, ref rect); } } // No top most SetWindowPos(process.MainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); // Replacer la fenêtre MoveWindow(process.MainWindowHandle, 0, 0, _width, _height, true); } // Focus Task.Factory.StartNew(() => { while (_enabled) { Thread.Sleep(200); _activateHook = GetForegroundWindow() == process.MainWindowHandle; } }); // Hook Task.Factory.StartNew(() => { _globalHook = Hook.GlobalEvents(); if (_isFullscreenGregware && !_isGentool) { _globalHook.MouseMoveExt += GlobalHookMouseMoveExt; } if (_isScrollGregware) { _globalHook.KeyDown += _globalHook_KeyDown; _globalHook.KeyUp += _globalHook_KeyUp; } }, CancellationToken.None, TaskCreationOptions.None, _uiScheduler); // Scroll Task.Factory.StartNew(() => { while (_enabled) { // Simuler en envoyant des pressions de touche du clavier Thread.Sleep(50); // Cumuler les actions de souris et clavier. EdgeZone edgeZoneCumul; if (!_activateHook) { edgeZoneCumul = EdgeZone.NONE; } else { if (_edgeZoneKeyboard == _edgeZoneMouse) { edgeZoneCumul = _edgeZoneKeyboard; // Tout va bien, on est d'accord } else if (_edgeZoneKeyboard == EdgeZone.NONE) { edgeZoneCumul = _edgeZoneMouse; // Que la souris en scroll } else if (_edgeZoneMouse == EdgeZone.NONE) { edgeZoneCumul = _edgeZoneKeyboard; // Que le clavier en scroll } else { edgeZoneCumul = EdgeZone.NONE; // Il y a conflit, on ne fait rien } } // Envoyer les keys switch (edgeZoneCumul) { case EdgeZone.NONE: // Toutes les touches UP if (_isDownAlt) { SendKey(KEYS_DX.ALT, false); } if (_isDownLeft) { SendKey(KEYS_DX.LEFT, false); } if (_isDownRight) { SendKey(KEYS_DX.RIGHT, false); } if (_isDownBottom) { SendKey(KEYS_DX.BOTTOM, false); } if (_isDownTop) { SendKey(KEYS_DX.UP, false); } break; case EdgeZone.L: // Left et Alt DOWN if (!_isDownAlt) { SendKey(KEYS_DX.ALT, true); } if (!_isDownLeft) { SendKey(KEYS_DX.LEFT, true); } // les autre UP if (_isDownRight) { SendKey(KEYS_DX.RIGHT, false); } if (_isDownBottom) { SendKey(KEYS_DX.BOTTOM, false); } if (_isDownTop) { SendKey(KEYS_DX.UP, false); } break; case EdgeZone.R: // Right et Alt DOWN if (!_isDownAlt) { SendKey(KEYS_DX.ALT, true); } if (!_isDownRight) { SendKey(KEYS_DX.RIGHT, true); } // les autre UP if (_isDownLeft) { SendKey(KEYS_DX.LEFT, false); } if (_isDownBottom) { SendKey(KEYS_DX.BOTTOM, false); } if (_isDownTop) { SendKey(KEYS_DX.UP, false); } break; case EdgeZone.T: // Top et Alt DOWN if (!_isDownAlt) { SendKey(KEYS_DX.ALT, true); } if (!_isDownTop) { SendKey(KEYS_DX.UP, true); } // les autre UP if (_isDownLeft) { SendKey(KEYS_DX.LEFT, false); } if (_isDownBottom) { SendKey(KEYS_DX.BOTTOM, false); } if (_isDownRight) { SendKey(KEYS_DX.RIGHT, false); } break; case EdgeZone.B: // Bottom et Alt DOWN if (!_isDownAlt) { SendKey(KEYS_DX.ALT, true); } if (!_isDownBottom) { SendKey(KEYS_DX.BOTTOM, true); } // les autre UP if (_isDownLeft) { SendKey(KEYS_DX.LEFT, false); } if (_isDownTop) { SendKey(KEYS_DX.UP, false); } if (_isDownRight) { SendKey(KEYS_DX.RIGHT, false); } break; case EdgeZone.LT: // Left, Top et Alt DOWN if (!_isDownAlt) { SendKey(KEYS_DX.ALT, true); } if (!_isDownTop) { SendKey(KEYS_DX.UP, true); } if (!_isDownLeft) { SendKey(KEYS_DX.LEFT, true); } // les autre UP if (_isDownRight) { SendKey(KEYS_DX.RIGHT, false); } if (_isDownBottom) { SendKey(KEYS_DX.BOTTOM, false); } break; case EdgeZone.LB: // Left, Bottom et Alt DOWN if (!_isDownAlt) { SendKey(KEYS_DX.ALT, true); } if (!_isDownBottom) { SendKey(KEYS_DX.BOTTOM, true); } if (!_isDownLeft) { SendKey(KEYS_DX.LEFT, true); } // les autre UP if (_isDownRight) { SendKey(KEYS_DX.RIGHT, false); } if (_isDownTop) { SendKey(KEYS_DX.UP, false); } break; case EdgeZone.RT: // Right, Top et Alt DOWN if (!_isDownAlt) { SendKey(KEYS_DX.ALT, true); } if (!_isDownTop) { SendKey(KEYS_DX.UP, true); } if (!_isDownRight) { SendKey(KEYS_DX.RIGHT, true); } // les autre UP if (_isDownLeft) { SendKey(KEYS_DX.LEFT, false); } if (_isDownBottom) { SendKey(KEYS_DX.BOTTOM, false); } break; case EdgeZone.RB: // Right, Bottom et Alt DOWN if (!_isDownAlt) { SendKey(KEYS_DX.ALT, true); } if (!_isDownBottom) { SendKey(KEYS_DX.BOTTOM, true); } if (!_isDownRight) { SendKey(KEYS_DX.RIGHT, true); } // les autre UP if (_isDownLeft) { SendKey(KEYS_DX.LEFT, false); } if (_isDownTop) { SendKey(KEYS_DX.UP, false); } break; } } }); }