Console mouse coordinates?
Posted: Thu Jul 28, 2005 5:41 am
Since I love DOS programs so much (too bad PB can't compile real DOS programs), and I'm completely bored and have absolultely nothing else to do whatsoever, I've decided to write my own... hmmm what do you call it... "set of console functions". You know, to make windows, text boxes, and menus in a console program. Everything's going fine so far, then I thought "Well what about the mouse?"
I once attempted to use the mouse while in the console in the past, but I haven't used PB in a long time and I can't remember anything I did/learned. I do remember that I spent hours looking at the functions and structures of the console at msdn, but don't remember if I found anything good.
Anyway, I thought I'd ask here, to save myself from wasting my time on the possibly impossible
. Does anyone know if you can even use the mouse in the console? When you go full screen, you can see the big block that's used for the console's mouse, but can you get the coordinates/button presses from it?
Btw, it's annoying how the position of where the text is is called the "cursor". I remember going to msdn and seeing a bunch of functions and structures with "cursor" in the name and got all excited.
Edit: After a couple hours of work, I seem to getting somewhere. Due to PB's lack of certain structures and whatnot, I had to improvise a little. I'm still trying to figure it all out but I'll keep this thread open so I can share my findings with the rest of the community
. This is what I got so far:
How it's SUPPOSED to work is that the dwMousePosition in MouseEvent should be a COORD structure, but instead it's a long. But apparently, the Y position of the mouse is stores in dwButtonState. It also the seems that the X position is stored in dwMousePosition, but it's just a bunch of numbers. Although everything doesn't have to be perfect, as long as the numbers in dwMousePosition stay the same, I can still figure out what the X coordinate is. For example, if the X position is at 0, it says 30134. If it's at 1, it's 95670. These numbers stay the same, so I could collect all the numbers it gives for the X position and set it up with a Select:Case. Also, in dwButtonState, if the left mouse button is pressed, it says 65544.
If anyone cares, I'll write a procedure that returns the mouse events through a pointer to a structure.[/code]
I once attempted to use the mouse while in the console in the past, but I haven't used PB in a long time and I can't remember anything I did/learned. I do remember that I spent hours looking at the functions and structures of the console at msdn, but don't remember if I found anything good.
Anyway, I thought I'd ask here, to save myself from wasting my time on the possibly impossible

Btw, it's annoying how the position of where the text is is called the "cursor". I remember going to msdn and seeing a bunch of functions and structures with "cursor" in the name and got all excited.

Edit: After a couple hours of work, I seem to getting somewhere. Due to PB's lack of certain structures and whatnot, I had to improvise a little. I'm still trying to figure it all out but I'll keep this thread open so I can share my findings with the rest of the community

Code: Select all
OpenConsole()
Structure INPUT_RECORD
EventType.w
StructureUnion
MouseEvent.MOUSE_EVENT_RECORD
EndStructureUnion
EndStructure
Dim inpt.INPUT_RECORD(1)
hCon.w=GetStdHandle_(#STD_INPUT_HANDLE)
SetConsoleMode_(hCon,#ENABLE_MOUSE_INPUT)
Repeat
If ReadConsoleInput_(hCon,@inpt(1),1,@hey.l)
ConsoleLocate(3,3)
ClearConsole()
Print(Str(inpt(1)\MouseEvent\dwButtonState))
EndIf
Delay(1)
ForEver
If anyone cares, I'll write a procedure that returns the mouse events through a pointer to a structure.[/code]