开发者

A function to detect if mouse moved in 5 seconds

开发者 https://www.devze.com 2023-03-05 04:40 出处:网络
I want to detect if mouse moved in 5 seconds, if yes time elapsed is showed. Here is my code, it seems ok but doesn\'t work correctly.

I want to detect if mouse moved in 5 seconds, if yes time elapsed is showed. Here is my code, it seems ok but doesn't work correctly.

void timer()
{
    if (ismouseclick(WM_开发者_StackOverflowMOUSEMOVE))
    {
        movetime=clock();
        clearmouseclick(WM_MOUSEMOVE);
    }
    if ((clock()-movetime)<6)
    {
        sprintf(time_str,"%d",clock();
        outtextxy(275,483,"Time: ");
        outtextxy(340,483,time_str);
    }
    else
    {
        setfillstyle(1,0);
        bar(275,483,370,500);
    }
}


Its about clock() function. You need to divide it to CLK_TCK (a constant) if you want seconds.

(clock()/CLK_TCK)


clock() typically returns the elapsed time in milliseconds (this is OS dependent, so check your OS's documentation), so when you are checking whether (clock() - movetime) < 6, that's not the elapsed time in actual seconds, but most likely milliseconds. Therefore you're probably not seeing the print-out you're expecting (i.e., it probably prints ever time you call timer(), or maybe it doesn't print at all).

0

精彩评论

暂无评论...
验证码 换一张
取 消