指针运动.为什么数字这么高?为什么它以块而不是恒定流的形式打印信息? [英] pointer motion. why are numbers so high? why does it print info in blocks not a constant stream?

查看:98
本文介绍了指针运动.为什么数字这么高?为什么它以块而不是恒定流的形式打印信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我正在尝试编写一个程序,在其中我需要报告每个鼠标移动的位置.我用PointerMotionMask掩码调用了XSelectInput()函数.一切似乎都可以正常工作,但是打印后的数字并没有在每次移动后出现,它们以块显示,而且event.xmotion.xevent.xmotion.y中的数字非常高,十万.
是什么原因导致这些数量庞大?
我的程序也是获取每个数字并立即报告它,还是存储在队列中并以块的形式发送到终端?
谢谢

Hi! I am trying to write a program where I need to report the position of every mouse motion. I have called the XSelectInput() function with a PointerMotionMask mask. Everything seems to work alright but the numbers after printing don't appear after every movement, they appear in blocks and also the numbers in event.xmotion.x and event.xmotion.y are very high, in the hundred thousands.
What is causing these large numbers?
Also is my program getting every number and reporting it immediately or is it being stored in a queue and sent in blocks to the terminal?
Thanks

这是我的事件循环:

while(1)
    {
        XNextEvent(display, &event);
        switch (event.type)
        {
            case Expose: 
                glClearColor( 1.0, 1.0, 0.0, 1.0 );
                    glClear( GL_COLOR_BUFFER_BIT );
                    glFlush();
                    glXSwapBuffers( display, glxwin );              
                break;
            case MotionNotify:
                printf("%d, %d", event.xmotion.x, event.xmotion.y);
                break;
            case ButtonPress: exit(1);
            default: break;     
        }   
    }

推荐答案

除了在末尾打印换行符之外,您还可以在末尾执行'\r',它将光标移动到现有行的开头,因此,每次都会在其自身上打印.为了使这项工作更好,请将数字格式更改为固定大小,例如:

Besides printing a newline at the end, you could also do a '\r' at the end it it will move the cursor to the beginning of the existing line, so it will just print over itself each time. To make this work better, change the digit formatting to be a fixed size, like:

printf("%4d, %4d  \r", event.xmotion.x, event.xmotion.y);
fflush(stdout) ;

这篇关于指针运动.为什么数字这么高?为什么它以块而不是恒定流的形式打印信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆