Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / mousex() and mousey() problem

Author
Message
Novaguy
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location:
Posted: 19th Apr 2010 06:00
do mousex() and mousey() only update positions after a sync? Here's a quick little tester I made:



Basically, it prints mousex() and mousey(), pauses for a bit (I didn't use "wait 1000" or anything like because seems to work with that), then prints the next mousex() and mousey() values. If you run this, the values are always the same. If you are moving the mouse, they really shouldn't be. I can only think that mousex() and mousey() don't update until some commands like "sync" or "wait" are called.

The reason I ask this is because I'm trying to detect whether the user clicks a button during a function. The function can potentially run forever, so this button stops it. The problem is that it only knows the initial mousex() and mousey() coordinates when the function first started going since theres no syncing or anything like inside of it. I'm not sure how to proceed.

As a side note, anyone else have a problem with the default DBPro editor with function minimizing? You press the little "-" next to a function and it minimizes, but then if you try typing below it sometimes the text doesn't show up. Is that just some odd thing with mine? Was wondering if there was a quick fix before I reinstalled.
Jaeg
20
Years of Service
User Offline
Joined: 16th Mar 2006
Location: Indiana
Posted: 19th Apr 2010 14:32
Don't you need str$(mousex()) and str$(mousey()) or is that just with the text command?

If you get mad and want to type something nasty about another person do this-Type what you want to say in the box then press ctrl-a and hit delete then type what you should say.
Link102
21
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 19th Apr 2010 14:54 Edited at: 19th Apr 2010 14:58
It's not clear whether your intentions are for the function to loop forever.
ifnot:
why don't you store the mouse's state at the top of your loop? or at the start of your function
ifso:
just make a loop inside your function, same way you did the main loop.

Quote: "Don't you need str$(mousex()) and str$(mousey()) or is that just with the text command?"


the print command can take just about all variables. You can chain them together with a comma (,)

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Apr 2010 15:09
Quote: "do mousex() and mousey() only update positions after a sync?"

No, only when windows messages are dealt with. That's generally during SYNC, but also on other occasions like WAIT, WAIT KEY or INPUT.

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 19th Apr 2010 18:03 Edited at: 19th Apr 2010 18:03
This works fine for me.



Novaguy
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location:
Posted: 19th Apr 2010 19:40 Edited at: 19th Apr 2010 19:55
@Link102
Let me elaborate on what I'm trying to do. I'm finishing up a sudoku solver, and the way it solves puzzles is by brute force. Some puzzles with multiple solutions (or invalid puzzles) take about an hour to solve. Basically, there is a recursive function that calls itself over and over until the puzzle is solved. There's no syncing, waiting, nor input during this cycle. Think of it as a potentially LONG for-next loop, like from i=0 to 99999999. While it is thinking, I want to give the user an option to move the mouse over to a "stop" button and click it. Obviously, the function would then terminate and a null solution is given. You can move the mouse while it is thinking, but mousex() and mousey() won't update values.

Now, instead of using

if mousex()>x and mousey()>y and mouseclick() then blah

where x and y are the coordinates of the button (it's in the bottom right hand corner of the screen), I used

while mousex()>x and mousey()>y and mouseclick()
blah
endwhile

It's a pretty ghetto fix, and I'd like a better way to do it. For now, though, it seems to work. Thanks KISTech

edit: Scratch that, it still doesn't seem to work.



No matter where you move the mouse, it never prints "IT WORKS!" Yes, my screen resolution was higher than 400x400 so it was possible for my mouse to reach those values. Also, if you run the program, the printed mousex() and mousey() still don't change ><
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Apr 2010 21:27
Quote: "FASTSYNC

This command will perform a regular SYNC command, and will skip processing a mandatory check for windows messages."

So it skips the processing of windows messages, which means it does not deal with the ones concerned with mouse movement either.

Just issue a SYNC once every second, or every 'n' loops or something.

Novaguy
17
Years of Service
User Offline
Joined: 1st Apr 2009
Location:
Posted: 19th Apr 2010 22:48 Edited at: 19th Apr 2010 22:49
My concern was that SYNC was slow, but I guess I could try that. Could I just do "wait 1" instead, or is SYNC faster than that?

edit: "wait 0" works. I think I'll just use that. Thanks all

Login to post a reply

Server time is: 2026-07-26 07:36:24
Your offset time is: 2026-07-26 07:36:24