(Note: Applied to Windows 10 and Python 3+)
I have already read a couple of postings regarding how to get cursor position using ANSI escape codes, but they offer no solution, at least not for Python. Wikipedia (https://en.wikipedia.org/wiki/ANSI_escape_code) includes the following ANSI seq: in its list of cursor management:
ESC 6n: DSR (Device Status Report) Reports the cursor position (CPR) to the application as (as though typed at the keyboard) ESC[n;mR, where n is the row and m is the column.)
So, if you apply this, using
print("3[6n"), what happens is that the response is "pushed" to keyboard and only after the script terminates, you get the following at the MS DOS prompt: ^[[7;11R (Numbers depend on the case).
Now, I really don’t see what does this serve for! So, my question is "Can we ‘finally’ get information about the cursor position using the mentioned conditions (Windows, ANSI codes and Python)?" … So that I can close this chapter once for all!
Source: Windows Questions