0

I want to check if the cursor is on a text/character or on blank console area. Is there any way to do this in the console Application in C#?enter image description here

Just want to know if the yellow cursor (in my case) is on one of the @S or on a blank console space.

thor
  • 21,418
  • 31
  • 87
  • 173
God
  • 1,238
  • 2
  • 18
  • 45
  • Store the map in an array and check the contents at the location you want to move to – Ewan Apr 18 '15 at 09:02
  • @Ewan you know whats the method for the checkup? Cursor.Position == array[i,j]? Thanks – God Apr 18 '15 at 09:04
  • You might want to read http://stackoverflow.com/questions/12355378/read-from-location-on-console-c-sharp. Basically, you have to keep track off all characters written to the console yourself. – Jesse Good Apr 18 '15 at 09:23
  • @JesseGood So i need to follow the link you posted? i didnt understand where is the comparison command? if (array[5,5] == '@') { // Do something } Where is that line comes to play? Thanks. – God Apr 18 '15 at 09:35
  • It is technically possible but requires pinvoke to call [ReadConsoleOutputCharacter](http://pinvoke.net/default.aspx/kernel32/ReadConsoleOutputCharacter.html). You are bound to learn more from doing it @Ewan's way, you can use that practice. – Hans Passant Apr 18 '15 at 09:54
  • @HansPassant Whoo, i dont understand a word from that pinvoke. Way out my level. Thanks for trying to help though. – God Apr 18 '15 at 09:59
  • @HansPassant From where i start? what libraries do i use for that? What [DllImport("kernel32.dll", SetLastError = true)] means? |: – God Apr 18 '15 at 10:01

1 Answers1

0

What works for me is:

if (Console.CursorLeft == checkedXPosition && Console.CursorTop == checkedYPosition)
{
  // Do something
}
God
  • 1,238
  • 2
  • 18
  • 45