Thread: event monitoring

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    event monitoring

    Hello everyone,

    I am searching for some possible way to monitor for an event in C programming. This application is written using DJGPP. Is there a method along the lines of GetEvent or WaitEvent that can be used. Currently the application is setup to run a loop over and over, monitoring for a keystroke or a mouseclick. That is eating up CPU badly because have a lot of people running this application on a server. Are there any suggestions?????????????

    Thanks,
    kendal

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    78
    What platform are you working with; Windows, Win32 Console, Linux,... ?

    If it is a windows server, this problem is very easy to fix... (but off topic for this forum)

    -Roger

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    First off, Thanks greatly for the fast reply.

    The pc's are connecting to the server through remote desktop connection. The pc's are running mostly Windows XP. The server is a Windows 2000 server. Once connected, they execute the program and run the program on the server. There are going to be numerous people accessing the application.

    Thanks,
    Kendal

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    78
    By remote desktop do you mean Terminal Services?

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Yes

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Doesn't sound too kosher.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Off to the Windows forum...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> Currently the application is setup to run a loop over and over, monitoring for a keystroke or a mouseclick.

    I'm not totally sure what you are doing, because you have not really answered the question about GUI/Console. The answer would depend upon that, both are quite straight forward.

    In a GUI, Just put appropriate handlers for the generated messages in your Windows processing loop.

    In a Console, use keyboard and mouse events, read part 5 of my tutorial. The first program demonstrates blocking loops.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User
    Join Date
    Jan 2003
    Posts
    78
    Originally posted by adrianxw
    read part 5 of my tutorial.
    Nice work, Adrian!
    Last edited by Rog; 08-01-2003 at 07:03 AM.

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Adrianxw,

    Thanks so much for the reply and the link to your tutorial. That is some very interesting stuff. It works great in DevC++ as a C++ project. If I try to compile it as a C project, I get a list of errors. Dev's error messages could not be any more vague. What changes when trying to compile as a C project and a C++ project????? How would I get that stuff to work as a C project? Ideally, my administrator wants to implement this into a DJGPP application.

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    You don't say which program you are using, so I'll use the first as an example. I started a new console project in VC and added the source file with a .c extension rather than .cpp.

    To get it to compile, I had to change the "cout" statements to printf() function calls. I had to comment out the iostream include and the namespace directive, and include <stdio.h>, then I had to change the type "bool" to "boolean" It then compiled and ran.

    Code:
    #include <windows.h>
    #include <stdio.h> 
    //#include <iostream>
    //using namespace std;
    
    int main()
    {
        HANDLE hIn;
        HANDLE hOut;
        COORD KeyWhere;
        COORD MouseWhere;
        COORD EndWhere;
        boolean Continue = TRUE;
        int KeyEvents = 0;
        int MouseEvents = 0;
        INPUT_RECORD InRec;
        DWORD NumRead;
    
        hIn = GetStdHandle(STD_INPUT_HANDLE);
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    //    cout << "Key Events   : " << endl;
    //    cout << "Mouse Events : " << flush;
        printf("Key Events   : \n");
        printf("Mouse Events : ");
    
        KeyWhere.X = 15;
        KeyWhere.Y = 0;
        MouseWhere.X = 15;
        MouseWhere.Y = 1;
        EndWhere.X = 0;
        EndWhere.Y = 3;
    
        while (Continue)
        {
            ReadConsoleInput(hIn,
                             &InRec,
                             1,
                             &NumRead);
    
            switch (InRec.EventType)
            {
            case KEY_EVENT:
                ++KeyEvents;
                SetConsoleCursorPosition(hOut,
                                         KeyWhere);
    //            cout << KeyEvents << flush;
                printf("%d",KeyEvents);
                if (InRec.Event.KeyEvent.uChar.AsciiChar == 'x')
                {
                    SetConsoleCursorPosition(hOut,
                                             EndWhere);
    //                cout << "Exiting..." << endl;
                    printf("Exiting...\n");
                    Continue = FALSE;
                }
                break;
    
            case MOUSE_EVENT:
                ++MouseEvents;
                SetConsoleCursorPosition(hOut,
                                         MouseWhere);
    //            cout << MouseEvents << flush;
                printf("%d",MouseEvents);
                break;
            }
        }
    
        return 0;
    }
    If that doesn't work, I'll need to know where it is failing and what error message you are getting.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Originally posted by gvector1
    Adrianxw,

    Thanks so much for the reply and the link to your tutorial. That is some very interesting stuff. It works great in DevC++ as a C++ project. If I try to compile it as a C project, I get a list of errors. Dev's error messages could not be any more vague. What changes when trying to compile as a C project and a C++ project????? How would I get that stuff to work as a C project? Ideally, my administrator wants to implement this into a DJGPP application.
    For heaven's sake, why DJGPP? Is there even a version that compiles for Windows? DJGPP is basically a DOS Protected Mode compiler.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #13
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    For heaven's sake, why DJGPP? Is there even a version that compiles for Windows? DJGPP is basically a DOS Protected Mode compiler.
    We are trying to complete phase 1 of a project. It was built using code written by my administrator in the 80s. He always used DJGPP. He had about 250,000 lines of code to pull from so that is what he used. We are just trying to get everything up and running, and then I will work on converting it to a windows system by writing code in Studio .NET. I have been using C# lately.

    Thanks a million Adrianxw,
    You are a life saver,
    Kendal

  14. #14
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Adrianxw,

    I have another question for you about the readconsoleinput if you are there. I am sorry to bother you again, but I have a problem. I think this is a GCC specific question but here it goes. I was able to get the readconsoleinput code you had to compile under the MingW gcc. It will not compile under the DJGPP gcc. Any idea why????? The GCC compilers are both version 3.2. The only difference I could notice is that the MingW stated (mingw special 20020817-1) and the file sizes are different. Any ideas about what I would have to do to get readconsoleinput to compile under the DJGPP version of gcc???????? Any and all help is greatly appreciated.

    Thanks,
    Kendal

  15. #15
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    I've never used DJGPP. What errors are you getting on what lines?

    ***EDIT***

    Is the default "int" in DJGPP 16 or 32bit?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Actors, cues, event based logic.
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-27-2006, 10:58 PM
  3. XWindows- Close window event?
    By Exile in forum Linux Programming
    Replies: 8
    Last Post: 01-09-2005, 10:39 PM
  4. Replies: 2
    Last Post: 09-22-2003, 01:47 PM