1. Another Win32Lib question: captureMouse()
- Posted by Ben Logan <wbljr79 at HOTMAIL.COM>
Apr 08, 2000
-
Last edited Apr 09, 2000
I would like to get the value of a pixel on the screen but outside my
program's window. I tried it like this:
Use 'captureMouse(MainWin)' to send all mouse events to my main window.
When the desired button is pressed, calculate the *screen* coords from the
data passed to the onMouse(...) event handler, and data returned from
'getSize(MainWin)'.
Use getPixel(Screen,x,y) to get the pixel value at the calculated location.
Unfortunately, this didn't work. Any suggestions?
Thanks,
Ben
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
2. Re: Another Win32Lib question: captureMouse()
Have you tried getMousePos()? I have not used this yet but the WinLib docs
say this returns mouse position relative to the screen.
Judith
On Sat, 8 Apr 2000 20:08:23 EDT, Ben Logan <wbljr79 at HOTMAIL.COM> wrote:
>I would like to get the value of a pixel on the screen but outside my
>program's window.
>Thanks,
>
>Ben
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
3. Re: Another Win32Lib question: captureMouse()
- Posted by Ben Logan <wbljr79 at HOTMAIL.COM>
Apr 09, 2000
-
Last edited Apr 10, 2000
>From: Judith Evans <camping at FLASH.NET>
>
>Have you tried getMousePos()? I have not used this yet but the WinLib docs
>say this returns mouse position relative to the screen.
>
>Judith
I tried it after reading your email, and it still won't let me retrieve the
color value of a pixel outside my program's window. Maybe it's not
possible?
Thanks,
Ben
>On Sat, 8 Apr 2000 20:08:23 EDT, Ben Logan <wbljr79 at HOTMAIL.COM> wrote:
>
> >I would like to get the value of a pixel on the screen but outside my
> >program's window.
> >Thanks,
> >
> >Ben
> >______________________________________________________
> >Get Your Private, Free Email at http://www.hotmail.com
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
4. Re: Another Win32Lib question: captureMouse()
Ben,
Sorry to be so late responding but yesterday I was building picket fencing.
If I understand your original question: you are trapping the mouse x,y and
then press a button to activate getPixel for the x,y location?
Are you sure that when you move the mouse to the button you are not trapping
the x,y position at that time (meaning at the button) thus being inside the
window?
Judith
On Sun, 9 Apr 2000 20:56:01 EDT, Ben Logan <wbljr79 at HOTMAIL.COM> wrote:
>I tried it after reading your email, and it still won't let me retrieve the
>color value of a pixel outside my program's window. Maybe it's not
>possible?
>
>Thanks,
>
>Ben
>
5. Re: Another Win32Lib question: captureMouse()
- Posted by Ben Logan <wbljr79 at HOTMAIL.COM>
Apr 11, 2000
-
Last edited Apr 12, 2000
>From: Judith Evans <camping at FLASH.NET>
>
>Ben,
>Sorry to be so late responding but yesterday I was building picket fencing.
No problem.
>
>If I understand your original question: you are trapping the mouse x,y and
>then press a button to activate getPixel for the x,y location?
>
That's right.
>Are you sure that when you move the mouse to the button you are not
>trapping
>the x,y position at that time (meaning at the button) thus being inside the
>window?
>
I'm pretty sure that's not happenning, because it retrieves the pixel values
correctly as long as I click inside my program's window. It only doesn't
work when I click outside the window.
Thanks,
Ben
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
6. Re: Another Win32Lib question: captureMouse()
Maybe if you explained why you want to capture a pixel that is
outside of your window, then someone might be able to determine a way
to solve your problem in a different way. It is not a standard thing
to do things outside of your windows application. The desktop on your
computer is also a window and you may have communicate with that window.
I think you need to explain more about the reason for wanting to
capture a pixel outside of your window.
Bernie
7. Re: Another Win32Lib question: captureMouse()
Ben Logan wrote:
> I'm pretty sure that's not happenning, because
> it retrieves the pixel values correctly as long
> as I click inside my program's window. It only doesn't
> work when I click outside the window.
The captureMouse routine works oddly, and not the way I would have expected
it to. Basically, it only works as long as the mouse button is held down.
For example:
include win32lib.ew
constant
W = create( Window, "", 0, Default, Default, 100, 100, 0 )
procedure press()
captureMouse( W )
end procedure
onClick[W] = routine_id("press")
procedure mouse( integer event, integer x, integer y, integer shift )
repaintWindow( W )
setPosition( W, 1, 1 )
wPrintf( W, "%d, %d ", {x,y} )
end procedure
onMouse[W] = routine_id("mouse")
WinMain( W, Normal )
If you click in the window and keep the mouse held down, the mouse will
continue to track. As soon as you release the mouse button, tracking stops.
This approach is problematic at best.
The Win32 documentation states:
"Only the foreground window can capture the mouse. When a background window
attempts to do so, the window receives messages only for mouse events that
occur when the cursor hot spot is within the visible portion of the window.
Also, even if the foreground window has captured the mouse, the user can
still click another window, bringing it to the foreground.
When the window no longer requires all mouse input, the thread that created
the window should call the ReleaseCapture function to release the mouse.
This function cannot be used to capture mouse input meant for another
process."
Perhaps a better approach would be to set up a timer and track the mouse
that way. I don't know how to dynamically read the state of the mouse
buttons, but you can instead read the state of the keyboard. For example,
the following code tracks the mouse and the state of the space bar.
include win32lib.ew
constant
Key = VK_SPACE,
W = create( Window, "Button Example", 0, Default, Default, 200, 100, 0 )
procedure timer( integer t )
integer state
sequence point, down, toggled
-- get the mouse position
point = getMousePos()
-- get state of key
state = c_func( xGetKeyState, { Key } )
-- down?
if and_bits( #8000, state ) then
down = "yes"
else
down = "no"
end if
-- toggled?
if and_bits( #1, state ) then
toggled = "yes"
else
toggled = "no"
end if
-- erase the window
repaintWindow( W )
-- mouse status
setPosition( W, 1, 1 )
wPrintf( W, "mouse: %d, %d key state: %x", point & state )
-- keyboard status
setPosition( W, 1, 32 )
wPrintf( W, "state: %x down: %s toggled: %s ", {state, down, toggled} )
end procedure
onTimer[W] = routine_id("timer")
-- set timer running
setTimer( W, 1, 100 )
WinMain( W, Normal )
With this approach, you can set up the timer routine to look for a special
key combination. When the user presses the key(s), use getMousePos to
determine where the mouse was pressed.
You can track the state of the shift keys with the following constants:
VK_SHIFT
VK_SHIFT
VK_CONTROL
VK_LSHIFT
VK_RSHIFT
VK_LCONTROL
VK_RCONTROL
VK_LMENU
VK_RMENU
So, for example, the code to watch for a CTRL+SHIFT+C key would be:
if and_bits( c_func( xGetKeyState( { VK_CONTROL } ), #8000 )
and and_bits( c_func( xGetKeyState( { VK_SHIFT } ), #8000 )
and and_bits( c_func( xGetKeyState( { 'c' ), #8000 ) then
-- your code here
end if
I hope this helps!
-- David Cuny