fixed comment into code

This commit is contained in:
2026-08-09 20:02:23 +05:00
parent 778fc1034b
commit 7e4e569d53
34 changed files with 332 additions and 306 deletions
+22 -20
View File
@@ -5,13 +5,13 @@ using CursorLang.Models;
namespace CursorLang.Services;
/// <summary>
/// Держит системный перехват Caps Lock и отличает короткое нажатие от удержания.
/// Holds the system Caps Lock hook and tells a short tap from a hold.
/// </summary>
/// <remarks>
/// Различить их можно только по факту отпускания клавиши, поэтому перехватываются
/// оба события — и нажатие, и отпускание. Заодно это единственный способ отменить
/// смену регистра: Windows переключает Caps Lock по событию нажатия, и пропустить
/// его «на всякий случай» нельзя.
/// They can be told apart only by the key being released, so both events are
/// intercepted — the press and the release. That is also the only way to cancel the
/// case change: Windows toggles Caps Lock on the press event, and letting it through
/// "just in case" is not an option.
/// </remarks>
public sealed class CapsLockHotkeyService : ICapsLockHotkeyService, IDisposable
{
@@ -28,7 +28,7 @@ public sealed class CapsLockHotkeyService : ICapsLockHotkeyService, IDisposable
public CapsLockHotkeyService(AppSettings settings)
{
_settings = settings;
_hook = new LowLevelKeyboardHook(OnKeyEvent);
_hook = new LowLevelKeyboardHook(HandleKeyEvent);
_holdTimer.Tick += OnHoldTimerTick;
}
@@ -48,9 +48,9 @@ public sealed class CapsLockHotkeyService : ICapsLockHotkeyService, IDisposable
ResetPress();
}
// При закрытии приложения событий уже никто не ждёт, поэтому в отличие
// от Stop состояние сбрасывается молча: очередь диспетчера в этот момент
// может быть закрыта
// When the application is closing, nobody is waiting for events any more, so
// unlike in Stop the state is reset quietly: the dispatcher queue may be shut
// down by that moment
public void Dispose()
{
_holdTimer.Tick -= OnHoldTimerTick;
@@ -60,10 +60,12 @@ public sealed class CapsLockHotkeyService : ICapsLockHotkeyService, IDisposable
_hook.Dispose();
}
// Вызывается системным хуком, то есть внутри разбора очереди сообщений.
// Здесь только учёт состояния: показывать окна и рассылать события отсюда
// нельзя — обработчик обязан вернуть управление за считанные миллисекунды
private bool OnKeyEvent(int virtualKey, bool isKeyDown)
// Called by the system hook, that is, inside message queue processing. Only state
// tracking belongs here: showing windows and raising events from here is not
// allowed — the handler must return control within a few milliseconds.
// In tests the key presses are fed here as well: there is no need to install a
// real keyboard hook just to check how presses are interpreted
internal bool HandleKeyEvent(int virtualKey, bool isKeyDown)
{
if (virtualKey != VirtualKeyCapsLock)
{
@@ -72,13 +74,13 @@ public sealed class CapsLockHotkeyService : ICapsLockHotkeyService, IDisposable
if (isKeyDown)
{
// Пока клавишу держат, Windows повторяет нажатие: отсчёт удержания
// ведём от первого события и на повторы не реагируем
// While the key is held, Windows repeats the press: the hold is counted
// from the first event and the repeats are ignored
if (!_isPressed)
{
_isPressed = true;
// Порог читаем при каждом нажатии: его меняют в настройках на лету
// The threshold is read on every press: it is changed in the settings on the fly
_holdTimer.Interval = _settings.CapsLockHoldDelay;
_holdTimer.Start();
}
@@ -109,8 +111,8 @@ public sealed class CapsLockHotkeyService : ICapsLockHotkeyService, IDisposable
HoldStarted?.Invoke(this, EventArgs.Empty);
}
// Событие уходит подписчикам после возврата из хука: они вправе показывать
// окна и делать что угодно ещё, не задерживая обработку нажатия
// The event reaches the subscribers after the hook returns: they are free to show
// windows and do anything else without holding up the handling of the key press
private void Notify(EventHandler? handler)
{
if (handler is not null)
@@ -119,8 +121,8 @@ public sealed class CapsLockHotkeyService : ICapsLockHotkeyService, IDisposable
}
}
// Перехват могли снять с зажатой клавишей — например, сняв галочку
// в настройках. Подсказку в этом случае нужно убрать
// The hook may have been removed with the key held down — by clearing the
// checkbox in the settings, for instance. The popup has to be taken down then
private void ResetPress()
{
_isPressed = false;