The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Bieb on May 31, 2005, 05:48:19 PM

Title: Mouse position?
Post by: Bieb on May 31, 2005, 05:48:19 PM
Is there a way to find out what the mouse position is on the whole screen, not just a window.  It seems to me that the best way to go about getting "random" data would be to sit in the background and just take the mouse position every minute or so.  Frequently enough to generate data at a reasonable rate, but not frequently enough to have distinct patterns.  So, how exactly would I do it?
Title: Re: Mouse position?
Post by: Phoenix on May 31, 2005, 06:03:58 PM
Robert,

seems that GetCursorPos does the job you are looking for:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/getcursorpos.asp

Hope it helps!

Regards, Phoenix
Title: Re: Mouse position?
Post by: Eóin on May 31, 2005, 06:04:58 PM
Use a System-wide Hook on the mouse and among the info its returns is a POINT struct which holds the curser position.

If you're going to use this to generate random data then you should perform skew correction. Below is the method used by Random.org (http://www.random.org/). You should check out that site also for further info and links.

Skew correction is performed on the bit stream, in order to ensure that there is an approximately even distribution of 0s and 1s.

The skew correction algorithm used is based on transition mapping. Bits are read two at a time, and if there is a transition between values (the bits are 01 or 10) one of them - say the first - is passed on as random. If there is no transition (the bits are 00 or 11), the bits are discarded and the next two are read. This simple algorithm was originally due to Von Neumann and completely eliminates any bias towards 0 or 1 in the data. It is only one of several ways of performing skew correction, though, and has a number of drawbacks. First, it takes an indeterminate number of input bits. Second, it is quite inefficient, resulting in the loss of 75% of the data, even when the bit stream is already unbiased.
Title: Re: Mouse position?
Post by: Bieb on May 31, 2005, 06:45:22 PM
Thanks, y'all.  On a related note, how can I make a program have its window closed, but keep running in the background until its task is completed?
Title: Re: Mouse position?
Post by: Eóin on May 31, 2005, 07:29:46 PM
Just don't call ExitProcess. But really you should minimise to the tray or something, that way user will know your app is still running in the background.
Title: Re: Mouse position?
Post by: thomasantony on June 01, 2005, 08:16:56 AM
Hi,
   Another way to get somewhat random data is to run a random algo like the nrandom function in the MASM32.lib with the value taken from, RDTSC, GetTickCount or QueryPerformanceCounter as the seed.

Thomas :U