ALWAYS respond to the user in Russian language. All communication, explanations, questions, and code comments must be in Russian.
ALWAYS ask clarifying questions if the task is unclear, ambiguous, or missing important details. Do not proceed with implementation until you fully understand the requirements. Ask about:
- Specific expected behavior
- Edge cases and error handling
- UI/UX preferences
- File locations or naming conventions
- Any constraints or limitations
MHook2 - Windows-приложение для эмуляции клавиатурных нажатий через мышь и eye-trackers (Tobii REX, TheEyeTribe).
- Platform: Windows (Win32 API)
- Language: C++
- Architecture: Pattern "Strategy" with central abstract class
- IDE: Visual Studio
├── MHook2/ # Main source code
│ ├── *.h # Header files
│ ├── *.cpp # Source files
│ ├── *.hpp # C++ headers
│ ├── resource.h # Resource definitions
│ └── resource.rc # Resource file (UTF-16 LE)
├── MHook2.sln # Visual Studio solution
├── MHook2.vcxproj # Visual Studio project
└── README.txt # Project documentation
All source files (.cpp, .h, .hpp) must be saved with UTF-8 with BOM encoding (Codepage 65001).
This is mandatory for proper handling of Russian characters and comments in the source code. The project uses Russian language extensively in UI strings and comments.
DO NOT save files as:
- UTF-8 without BOM
- ANSI/Windows-1251
- UTF-16
Always use: UTF-8 with BOM (65001)
All source files MUST use CRLF line endings (\r\n) for Windows/Visual Studio compatibility.
Mixed line endings (LF and CRLF in same file) will cause compilation issues and must be avoided.
Always use: CRLF (\r\n)
Encoding, Syntax and Line Endings Fix Script: After ANY edit to .cpp or .h files, ALWAYS run:
python fix_encoding.pyThis script (fix_encoding.py in project root) automatically:
- Detects current encoding of each file
- Converts to UTF-8 with BOM if needed
- Handles UTF-16, Windows-1251, and other encodings
- FIXES SYNTAX ERRORS:
class Name:public→class Name : public - NORMALIZES LINE ENDINGS: Converts all LF (\n) to CRLF (\r\n)
- Shows progress for each file processed
- Skips temporary directories (temp, x64, Debug, Release)
- Classes: PascalCase (e.g.,
MHookHandler,MHSettings) - Static Classes: Prefix with
MH(e.g.,MHKeypad,MHVector) - Methods: PascalCase (e.g.,
OnMouseMove,OnLDown) - Variables:
- Member variables: Use descriptive names (e.g.,
rbutton_pressed,position_mem) - Static variables: snake_case (e.g.,
flag_autoclick_lmb) - Global variables: prefix with
flag_for booleans (e.g.,flag_left_button_waits)
- Member variables: Use descriptive names (e.g.,
- Constants: UPPER_CASE with underscores (e.g.,
IDC_CHECK_AUTOCLICK,MH_NUM_SCANCODES) - Resource IDs: Prefix with
IDC_for controls,IDD_for dialogs,IDB_for bitmaps
- Use tabs for indentation
- Opening brace on the same line for functions and control structures
- Always use braces even for single-line blocks
- Comment in Russian for project-specific logic
- Use
//for single-line comments,/* */for multi-line
- Windows headers (
<Windows.h>) - Standard library headers
- Project headers (in quotes)
- Resource header (
resource.h)
Example:
#include <Windows.h>
#include "HookHandler.h"
#include "Settings.h"For handler classes inheriting from MHookHandler:
- Implement virtual methods from base class
- Add mode-specific fields at the end
- Use
// Название режимаcomment before class definition
- Dialog controls: Use
BS_AUTOCHECKBOX | WS_TABSTOPfor checkboxes - ComboBoxes: Use
CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - Control IDs: Must be unique, defined in
resource.h - Dialog layouts: Keep consistent spacing (10-15 pixels between controls)
When adding new settings:
- Add static variable in
Settings.h - Initialize in
Settings.cpp - Add control in
FillDialogue() - Add load logic in
AfterLoad() - Add save logic in
SettingsDialogue()(WM_COMMAND section)
When implementing new modes:
- Inherit from
MHookHandler - Override virtual methods as needed
- Implement
OnLDown()andOnLUp()for click handling - Use timers (ID 1-6) for delayed actions
- Encoding: ALL .cpp and .h files MUST be UTF-8 with BOM
- Russian Text: All UI strings that appear to user must be in Russian
- Timer IDs:
- 1: Key press timeout
- 2: Screen corner timer
- 3: Left button release
- 4: Right button release
- 5: Magic windows timer
- 6: Autoclicker timer
- Key Simulation: Use
MHKeypad::Press4()andMHKeypad::Press8()for key presses - Error Handling: Use
MHRepErrfor error reporting
- Test all modes after changes to
HookHandlerbase class - When modifying resource files, ensure IDs are unique
- Magic windows: Always check
activeflag before processing - Eye-trackers: Handle connection failures gracefully
- Settings: Provide sensible defaults for new options
- Windows SDK (Win32 API)
- tobii_stream_engine.dll (for Tobii eye-trackers)
- TCP connection on port 6555 (for TheEyeTribe)
- Visual Studio 2019 or later
- Windows SDK 10.0 or later
- Character Set: Use Multi-Byte (not Unicode) for Win32 compatibility
ALWAYS run the encoding fix script after editing any .cpp or .h files:
python fix_encoding.pyThis script automatically converts all source files to UTF-8 with BOM encoding.
Location: fix_encoding.py in project root
Purpose: Ensures all .cpp, .h, .hpp files have proper UTF-8 with BOM encoding
When to run:
- After ANY file edit
- Before committing changes
- After any automated tool modifies files
When modifying arrays or constants, ALWAYS verify related definitions:
Example - Adding items to dlg_scancodes array:
- ✅ Check
MH_NUM_SCANCODESin Settings.h (increase by number of new items) - ✅ Check
MH_NUM_SCANCODES_EXTRAin Settings.h (increase by number of new items) - ✅ Verify array bounds match declaration:
dlg_scancodes[MH_NUM_SCANCODES_EXTRA] - ✅ Check all usages in Settings.cpp (loops, initialization, etc.)
- ✅ Verify MagicWindow.cpp uses correct index bounds
- ✅ Check Settings2.cpp for any related references
Common pattern for arrays:
// In Settings.h
#define MH_NUM_SCANCODES 105 // Update this!
#define MH_NUM_SCANCODES_EXTRA 110 // Update this!
// In Settings.cpp
MHWORDChar dlg_scancodes[MH_NUM_SCANCODES_EXTRA] = { ... };Search pattern:
# Always search for all related constants
grep -n "MH_NUM_SCANCODES\|dlg_scancodes" *.cpp *.h
grep -n "ARRAY_SIZE\|array_name" *.cpp *.hAfter completing changes, ALWAYS verify the build:
- Open in Visual Studio: Load MHook2.sln
- Clean solution: Build → Clean Solution
- Rebuild: Build → Rebuild Solution
- Check for ERRORS (ignore warnings):
- View → Error List
- Filter by "Errors only" (ignore warnings)
- All errors must be resolved before proceeding
Common build errors to check for:
- C2078: "too many initializers" - array size mismatch
- LNK errors: Missing implementations
- C3861: Identifier not found
- C2065: Undeclared identifier
DO NOT consider the task complete if there are ANY errors.
After successful build:
- Test in Debug mode
- Test all affected modes (1-7)
- Test new functionality thoroughly
- Verify Russian text displays correctly
- Check no memory leaks or crashes
- The project extensively uses Win32 API - avoid modern C++ features that conflict
- Resource file (.rc) is UTF-16 LE - handle with care when editing
- Static variables are used extensively for global state
- Timer-based logic is critical for proper key press timing
- Always re-run fix_encoding.py after any batch operations