Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, July 27, 2009 12:38 PM | 1 vote
How do I use the Mouse in a C# Console Application? Any simple DOS Programm (eg. EDIT.COM from system32 Directory) can use the Mouse but I still can't find out, how to use it. I don't want use relative screen coordinates, because a User may have different Font style for the Console Window and I can not find out how big the Console Window in Screen Coordinates is, the WindowWidth and WindowHeight Property of the Console Class gives me only the values in chars (normally 80x25).
If I switch to Fullscreen with ALT+ENTER I can see the Mouse Cursor in my Application and can move it, but i can not capture the Events.
All replies (6)
Monday, July 27, 2009 9:04 PM âś…Answered | 1 vote
Edit.com is not a console application, it is a DOS application which is run in Window's DOS emulator. Unless you can find some old DOS disks to install and a really old C compiler, you won't be able to write a DOS app (things were much simpler in those days).
It is not impossible, it's just going to be a lot of work for you. You cannot use System.Console, so you have two choices:
- Do it in C# with a lot of p/invoke to the console API.
- Do it in C++.
There is a third option of course, and a much better one:
- Give up the console and write a GUI. Most Telnet applications have "gone GUI" a decade ago (or more).
Monday, July 27, 2009 1:24 PM | 1 vote
Since the .NET designer who wrote the System.Console class decided it wasn't important for us to create mouse-interactive console applications (and rightly so), you have no choice but to write your own Console. And I mean pretty much all of it.
http://msdn.microsoft.com/en-us/library/ms682010(VS.85).aspx
Good luck.
Monday, July 27, 2009 1:36 PM | 1 vote
You can try P/Invoke-ing SetConsoleMode with ENABLE_MOUSE_INPUT.http://blog.voidnish.com
Monday, July 27, 2009 1:38 PM
But since you will never detect mouse events without calling ReadConsoleInput, and doing so means fully implementing both keyboard and mouse input (and associated streams), that "quick fix" won't help.
It might be possible to hack something together with PeakConsoleInput for just mouse data though.. I would have to spend way more time thinking about it to be sure. Most likely since the System.Console class already calls ReadConsoleInput, you'll never see any mouse events. They get swallowed.
Monday, July 27, 2009 6:43 PM
So I can forget the Mouse cursor in my C# Console Application forever?
It is hard to navigate trough a List with 60 Links with only the Arrow Keys
oh, I'd like to use the Mouse Cursor to implement a "Telnet Like" Internet Service based on http Protocol and I hate using only the Keyboard. Even edit.com can use the Mouse Cursor..., if someone is interested in, i can give the Source Files
Wednesday, July 29, 2009 5:50 PM
Number one sounds interesting...