shablon
Download scriptThis script is designed to act as a background monitoring tool that tracks user interactions with your computer in real-time. Instead of interacting directly with the price charts or executing trades, its primary purpose is to detect and record human activity—specifically keyboard presses and mouse clicks—and identify which application is currently being used when those actions occur.
How it Works
The script operates in a continuous loop, constantly "listening" for input from the operating system. It performs three specific checks simultaneously:
- Keyboard Tracking: It identifies if a key has been pressed on your keyboard. If an interaction is detected, it captures the specific code associated with that key.
- Mouse Tracking: It monitors mouse activity. It is programmed to distinguish between actual clicks or button presses and simple cursor movements (meaning it ignores you simply moving the mouse around the screen).
- Window Identification: It simultaneously checks which window is currently "active" or in focus on your desktop.
What Happens with the Data
Every time you press a key or click the mouse, the script combines this information into a log entry. It then prints a message to the internal system log containing:
- The specific ID of the key or mouse button used.
- The name of the software window where that action took place.
Key Technical Behavior
- Real-Time Monitoring: The script checks for these actions every 100 milliseconds, ensuring that it captures interactions almost instantly as they happen.
- System Integration: It uses external libraries to bridge the gap between the trading platform and your computer's hardware, allowing it to "see" activity outside of the software itself.
- Initialization & Cleanup: The script automatically prepares its connection to your system's input drivers when you start it and properly disconnects those resources when you stop it, ensuring it doesn't leave unnecessary processes running in the background.
//+------------------------------------------------------------------+
//| shablon.mq4 |
//| Viatcheslav Suvorov |
//+------------------------------------------------------------------+
#property copyright "Viatcheslav Suvorov"
#property show_inputs
#include <WinUser32.mqh>
#import "IdleLib.dll"
int GetLastKeyWP();
int GetLastMouseWP();
int IdleLibInit();
int IdleLibUnInit();
string GetActiveWndName();
#import
int start()
{
IdleLibInit();//èíèöèàëèçèðóåì Dll äëÿ ïåðåõâàòà ñîáûòèé
bool NeedLoop=true;
while(NeedLoop){
int lastkey=GetLastKeyWP();//Îïðàøèâàåì êîä ïîñë. êëàâèøè
int lastmouse=GetLastMouseWP();//Îïðàøèâàåì êîä ìûøè
string lastwnd=GetActiveWndName();//Èìÿ îêíà Metatrader ãäå ïðîèçîøëî ñîáûòèå
if ((lastkey!=0) && (lastwnd!="")) {
Print("Êîä íàæàòîé êëàâèøè=",lastkey," èç îêíà ",lastwnd);
}
if ((lastmouse!=0) && (lastwnd!="") && (lastmouse!=512)) {//îòðàæàåì âñå ñîáûòèÿ êðîìå äâèæåíèÿ ìûøè
Print("Êîä ìûøè=",lastmouse," èç îêíà ",lastwnd);
}
Sleep(100);
}//while
return(0);
}
void deinit()
{
IdleLibUnInit();
}
Comments