Jump to content

Hey guys, I am looking to find a way to detect the position of the cursor in a Python program , the entire program is using unicode characters to render a UI, which I have nearly finished writing the basic code for. However, I am looking to detect the cursor positon within the window so that I can have mouse input within the program. I know I can use Tkinter to do this but that would require a complete rewrite of my code, and not only that but the online IDE I am using does not support Tkinter, and I'm sure the reason for that would be obvious.

 

So, I am left with finding a way to detect the cursor's position. If it comes down to it I'll manage cursor position using the keyboard and add in mouse functionality before releasing if I really have to.

 

For those wondering what happened to Nostradamus:

Spoiler

Incase anyone is wondeing what happened to the Nostradamus Programming Language, I will still be working on it, but as part of the game I am writing. After I complete the first milestone for the game, I will make a standalone version of the Nostradamus Programming Language available on my website, that has been integrated with the rendering engine for the game I am working on. 

 

Now, I am not going into details right now but I will say it's going to be an interesting project to work on to say the least.

 

My procrastination is the bane of my existence.

I make games and stuff in my spare time.

 

 

Link to comment
https://linustechtips.com/topic/551021-detecting-cursor-in-python/
Share on other sites

Link to post
Share on other sites

Within the CLI shell (terminal/cmd/whatever) ?

Anyway , without using something like tkinter , or other modules , you can use platform-specific APIs to get the mouse position.

With windows :

To get the position :

win32api.GetCursorPos(point)

To get more info on the cursor :

flags, hcursor, (x,y) = win32gui.GetCursorInfo()

 

Or maybe you could use curses.

https://docs.python.org/2/howto/curses.html

That could work. But then again , curses hasn't officially been ported to Windows. If you are working on Windows, then there's this http://effbot.org/zone/console-index.htm#documentation .

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to post
Share on other sites

1 minute ago, Nineshadow said:

Within the CLI shell (terminal/cmd/whatever) ?

Yep, the entire UI will be drawn within the CLI shell. Similarly to how programs such as Xtree would render back in the DOS days

 

for an idea of what the UI  style might look like, think of this, of course the colorscheme is debatable:

xtree.gif

If you've never written this style of UI before, the string manipulation gets pretty hardcore.

My procrastination is the bane of my existence.

I make games and stuff in my spare time.

 

 

Link to post
Share on other sites

Just now, UnbrokenMotion said:

Yep, the entire UI will be drawn within the CLI shell. Similarly to how programs such as Xtree would render back in the DOS days

 

for an idea of what the UI  style might look like, think of this, of course the colorscheme is debatable:

xtree.gif

If you've never written this style of UI before, the string manipulation gets pretty hardcore.

Are you using curses?

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to post
Share on other sites

6 minutes ago, Nineshadow said:

Are you using curses?

I had to do a quick google search on this.

 

I'm guessing it's designed for making programs that need this type of interface, it appears to have a cursor function too.

I'm already too deep into this project to start practically back over from scratch... Would I be able to use this without having to rewrite the entirety of my code?

My procrastination is the bane of my existence.

I make games and stuff in my spare time.

 

 

Link to post
Share on other sites

Just now, UnbrokenMotion said:

I had to do a quick google search on this.

 

I'm guessing it's designed for making programs that need this type of interface, it appears to have a cursor function too.

I'm already too deep into this project to turn back... Would I be able to use this without having to rewrite the entirety of my code?

No idea honestly.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to post
Share on other sites

Just now, Nineshadow said:

No idea honestly.

I saw the win32api detection method in your first reply, and while that might work, i'd have to wait until right before releasing the first version so that I can write and test the code for it before compiling everything on my computer. But, it's a lot better than having to re-write the code should tkinter require it.

My procrastination is the bane of my existence.

I make games and stuff in my spare time.

 

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×