gpt4 book ai didi

值的比较不会立即起作用

转载 作者:太空宇宙 更新时间:2023-11-03 23:46:45 26 4
gpt4 key购买 nike

我正在编写一个应用程序来计算我们产品的鼠标延迟时间。

它的工作方式是发送鼠标移动,并测量从那时到我们在屏幕上获得像素变化之间的时间。

为什么这个延迟会影响程序。

int check_for_pixel_change() {

// Gets the pixels R value
unsigned char value = *((unsigned char *) (0x100));

// If this delay is not here then the loop will always return 1
usleep(5);

if(value == (0x80)) return 0;
else return 1;
}

int main() {
// Send move / start timer

while(check_for_pixel_change());

// stop timer
return 0;
}

最佳答案

这是有效的代码。

感谢@barak-manos && @santosh-a。

我需要将 char 更改为 volatile,因为它会被不同的程序不断更改。

int check_for_pixel_change() {

// Gets the pixels R value
volatile unsigned char value = *(volatile unsigned char *) (0x100);

if(value == (0x80)) return 0;
else return 1;
}

int main() {
// Send move / start timer

while(check_for_pixel_change());

// stop timer
return 0;
}

关于值的比较不会立即起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30752238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com