Exemple #1
0
inline void SPEEDSCTRL::LimitSpeed(double TotalData, DWORD Unit, double Speed_Per_Sec)
{
	if(Speed_Per_Sec == 0)
		return;
	DataUnit = Unit;
	CurrTime = GetCurrTime();
	DoDelay(BaseTime, CurrTime, TotalData - PrevSize, Speed_Per_Sec/1000);
	PrevTime = CurrTime;
	PrevSpeed = Speed_Per_Sec/1000;
}
Exemple #2
0
//---------------------------------------------------------------------------
//do inter-key delay
void TPushKeys::DoKeyDelay()
{
	if (Process==NULL)
	{
		//timed delay
		DoDelay(KeyDelayValue);
	}
	else //wait for input buffer to empty from process passed to onpus event
	{
		WaitForInputIdle(Process,ProcessWait);
	}

}
Exemple #3
0
//-----------------------------------------------------------
//friend of TPK on key handler
//extract key string and pass to handler
//process keypushes etc on return
void OnKeyHandler(bool IsFnKey,CString Key)
{
	CString k=Key;
	CString uk=k.UpperCase();

	int count;
	bool CallKeyHandler=false;

	//delay
	bool IsSleep=uk.Pos("SLEEP")==1;

	//*********************
	//clear clipboard
	bool IsClearClip=uk.Pos("EMPTYCLIP")==1;

	//run
	bool IsRun=uk.Pos("RUN ")==1;

	//{\0xxx}
	bool IsDirect=k.Pos("\\")==1 && k.GetLength()>1;

	if (k=="\\")
	{
		IsDirect=false;
		IsFnKey=false;
	}

	//function key? or clear clipboard or run
	if(IsFnKey || IsSleep || IsDirect  || IsClearClip || IsRun)
	{
		//get count value & strip out count characters
		if (!IsRun)
		{
			count=GetFunctionKeyCount(k);
		}

		if(IsAFunctionKey(uk) || IsDirect)
		{
			//not a control key?
			if (GetControlKey(uk)==(byte)-1)
				k="{"+uk+"}";

			CallKeyHandler=true;

		}

		//sleep or clear clipboard or run
		if (IsSleep || IsClearClip || IsRun)
		{
			k="{"+Key.UpperCase()+"}";
			CallKeyHandler=true;
		}
	}
	else
	{
		if (k.GetLength()==1)
		{
			CallKeyHandler=true;

		}
	}

	if (!CallKeyHandler)
		return;


	//set up shiftstate to pass here
	//**************************
	TShiftState KeyState,CopyOfKeyState;
	if (ShiftOn)
		KeyState<<ssShift;

	if (ControlOn)
		KeyState<<ssCtrl;

	if (AltOn)
		KeyState<<ssAlt;

	//keep a copy
	CopyOfKeyState=KeyState;

	//pass to onkey & delay handler
	//************************
	GTPK->HandleOnKeyEvent(k,KeyState);

	//returned keys
	//************************
	CString returned=k;
	int rl=returned.GetLength();
	uk=returned.UpperCase();

	if (rl==0)
		return;

	//process returned shiftstate
	//**************
	//changed?
	if (KeyState!=CopyOfKeyState)
	{
		//set key states
		SetKeyStates(KeyState);
	}

	//process keys returned
	//***************************
	IsSleep=uk.Pos("{SLEEP")==1;

	//clear clipboard
	IsClearClip=uk.Pos("{EMPTYCLIP")==1;

	//run
	IsRun=uk.Pos("{RUN ")==1;

	//single key(s)?
	if (rl<3)
	{
		PushAString(returned);
	}
	else
	{
		if (returned[1]=='{' && returned[rl]=='}')
		{
			//strip out braces
			CString fk=returned.SubString(2,rl-2).UpperCase();

			bool IsNL=k=="{NEWLINE}" || uk=="{NL}";

			//is it a function key?
			if(IsAFunctionKey(fk) && !IsNL)
			{
				PushFnKey(fk);
			}
			//CRLF
			else if (IsNL)
			{
				// New line = Carriage return & Line Feed = ^M^J
				for (int i=0;i<count;i++)
				{
					if (DOSKey)//ANSI equivalent
					{
						PushCTRLKey('M');
						PushCTRLKey('J');
					}
					else
					{
						UINT ScanKey = MapVirtualKey(VK_RETURN, 0);
						PressKey(VK_RETURN,ScanKey);
						ScanKey = MapVirtualKey(VK_LINEFEED, 0);
						PressKey(VK_LINEFEED,ScanKey);
					}
				}
			}
			//direct {\xxxx}
			else if(fk.Pos("\\")==1 && fk.GetLength()>1)
			{
				if (fk.GetLength()>1)
				{
					//start key presses
					ALTOn();

					//step along numbers
					for (int numpointer=2;numpointer<=fk.GetLength();numpointer++)
					{
						char number=fk[numpointer];

						if (number>='0' && number<='9')
						{
							//get numpad key
							byte npk[]={VK_NUMPAD0,VK_NUMPAD1,VK_NUMPAD2,VK_NUMPAD3,VK_NUMPAD4
								,VK_NUMPAD5,VK_NUMPAD6,VK_NUMPAD7,VK_NUMPAD8,VK_NUMPAD9};

							byte numpadkey=npk[number-'0'];

							//press key
							PressKey(numpadkey,MapVirtualKey(numpadkey,0));
						}

					}

					//all done
					ALTOff();
				}
			}
			//delay
			else if(IsSleep)//sleep
			{
				int count=GetFunctionKeyCount(fk);
				DoDelay(count);
			}
			//clear clipboard
			else if (IsClearClip)
			{
				int count=GetFunctionKeyCount(fk);
				for (int c=0;c<count;c++)
				{
					if (OpenClipboard(NULL))
					{
						EmptyClipboard();
						CloseClipboard();
					}
				}
			}
			else if (IsRun)//run
			{
				CString runcmd=Key.SubString(4,fk.GetLength());
				WinExec(runcmd.c_str(),SW_SHOWNORMAL);
			}

			else //do single keys
			{
				PushAString(returned);
			}
		}
		else
		{
			PushAString(returned);
		}
	}

	//reset changed shiftstate
	//**************
	//changed?
	if (KeyState!=CopyOfKeyState)
	{
		//reset key states
		SetKeyStates(CopyOfKeyState);
	}

	//do inter-key delay if not a sleep command
	if(!IsSleep)
	{
		GTPK->DoKeyDelay();
	}
}
Exemple #4
0
//---------------------------------------------------------------------------
//method to simulate key presses
//returns false if window title contained a value but window could not be found
HWND __fastcall TPushKeys::PushMethod(CString k)
{
	//active flag
	fIsPushing=true;

	//calculate default key delay value
	KeyDelayValue=0;
	if (fDelay!=0)
	{
		//value specified
		if (fDelay>0)
		{
			KeyDelayValue=fDelay;
		}
		else //negative==use keyboard delay value
		{
			//get value
			DWORD kbs;
			SystemParametersInfo(SPI_GETKEYBOARDSPEED,0,&kbs,0);

			//i think this is how it works
			kbs+=2;
			KeyDelayValue=1000/kbs;

		}

	}

	//no title specified?
	if (fWindowTitle=="")
	{
		TargetWindow=GetForegroundWindow();
	}
	else
	{
		//enum windows & match window title
		FindWindowTitle();
	}


	//pass window handle, activation flag, Process handle & wait time to OnPush event handler
	bool Activate=true;
	//default process handle & wait time
	Process=NULL;
	ProcessWait=0;

	if (OnPush)
	{
		OnPush(this,TargetWindow,Activate,Process,ProcessWait);
	}


	//ok to push flag
	bool DoPushing=true;

	//set target window as active?
	if (Activate)
	{
		//activate window if valid
		if (TargetWindow!=NULL && IsWindow(TargetWindow))
		{
			SetForegroundWindow(TargetWindow);
		}
		else //no pushing to be done
		{
			TargetWindow=NULL;
			DoPushing=false;
		}
	}

	//global target
	GTargetWindow=TargetWindow;
	GTrackTarget=Activate ? fTrackTarget : false;

	//ok to push?
	if (DoPushing)
	{
		//push the keys
		DoPushKeys(this,k);
	}

	//return focus?
	if (fReturnFocus)
	{
		//give time for key presses to complete
		DoDelay(100);

		HWND ThisWindow=((TForm*)(this->Owner))->Handle;
		if (IsWindow(ThisWindow) && ThisWindow!=NULL)
		{
			SetForegroundWindow(ThisWindow);
		}
	}

	//all done
	fIsPushing=false;

	return TargetWindow;


}
void WSortView::OnAccess()
{
    ++g_access_count;

    DoDelay(g_delay);
}