| | |
Windows Console Mouse operations
Thread Solved
![]() |
Hi all, i'm looking into doing a little bit of work with the mouse in console applications on windows. I'm using windows.h to get access to functions such as ReadConsoleInput. I've created a simple program that just prints a string whenever the left most mouse button is clicked. However sometimes it works fine sometimes it doesn't. By doesn't work it seems to be that when i run it if my curser is out side the console window then when i move my mouse into the console window it crashes. If it is inside to begin with then i seems to be ok....quite odd.
I was wondering if you could shed some light on where i have gone wrong thanks.
Chris
I was wondering if you could shed some light on where i have gone wrong thanks.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> using namespace std; int main(void){ HANDLE stin = GetStdHandle(STD_INPUT_HANDLE); DWORD NumRead; DWORD numEvents; while(1){ GetNumberOfConsoleInputEvents(stin, &numEvents); INPUT_RECORD *inputStat = new INPUT_RECORD[numEvents]; ReadConsoleInput(stin, inputStat, 1, &NumRead); if(NumRead != 0){ for(int i = 0; i < NumRead; i++){ if(inputStat[i].EventType==MOUSE_EVENT){ if (inputStat[i].Event.MouseEvent.dwButtonState & 0x0001){ std::cout << "Clicked\n"; } } } delete inputStat; } } return 0; }
Chris
Knowledge is power -- But experience is everything
How silly of me, Ye i was just tyrying to get it working before i set up failure checks, thanks for that. It was 2 silly mistakes. It's because i originally had it set up not using an array just to process one event and din't think to update those bits lol
Thanks,
Chris
Thanks,
Chris
Knowledge is power -- But experience is everything
![]() |
Similar Threads
- hijackthis.exe is not a valid win32 application (Viruses, Spyware and other Nasties)
- control panel won't open and can't remove hacktool.root kit (Viruses, Spyware and other Nasties)
- help I need to remove this Trojan.Cachecachekit (Viruses, Spyware and other Nasties)
- window freeze when using canon printer (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: reading file
- Next Thread: Need help in finding correct method for my program!
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






