News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

easiest way to determine if mouse is clicked

Started by Telefunken, September 02, 2006, 06:10:19 PM

Previous topic - Next topic

Telefunken

I'm working on a new project and i need an easy way to determine when the mouse is clicked - in our outside of the program window.
I've found NM_CLICK, but that only works inside the window when the user interacts with a control.

All ideas are helpful, Thanks

w0lfshad3

AFAIK mouse messages concern the focus in WinAPI, thus maybe get the screen device context and process WM_MOUSEACTIVATE?
Anyway you need the actual hardware "message" and trap it somehow.
I don't remember clearly now but mouse events as in buttons pushed are regarded by windows the same as keyboard events i think and they have codes, defined in MACROS as VK_LBUTTON, VK_RBUTTON and VK_MBUTTON... EDIT: i think this is it.

Charles Petzold, Programming windows 5th edition
QuoteVirtual Key Codes
The virtual key code is stored in the wParam parameter of the WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, and WM_SYSKEYUP messages. This code identifies the key being pressed or released.

Telefunken

so to actually implement that into my code it would be something like

.if eax==WM_KEYDOWN
   .if wParam==VK_LBUTTON
          do something here
   .endif
.endif


??


EDIT: That code i have up there doesn't work  :P. Even if it did though, it would still only know you pressed the L button when the window was active.

w0lfshad3

Some1 here should give you the way to use OEM scan codes obtained from ROM BIOS.

And well ya i told you its probably bent on the focus of the window, however there could be "haxx" ways of getting around that, but i'm not aware of any.

Telefunken

i hope i don't get in trouble for saying this :P
but... maybe i could look at the source of some script kiddie keylogger and see how it gets keyboard input or mouse input and use it in my program.

and if the mods are wondering, my program isn't going to be anything malicious. i'm just wanting to kill the proccess of a window the user clicks on.

if someone's already done what i'm talking about, don't post spoilers. i want to write this on my own, but this is the only thing im having trouble with.

Jackal

perhaps the API SetWindowsHookEx will be what you need along with WH_MOUSE.

Ratch

Telefunken,

     How about processing the WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN, etcetera series of messages?  This is only part of the set of  messages windows can send a program when the mouse goes to work.  Perhaps you want to capture the mouse also.  Ratch

w0lfshad3

Quote.if eax==WM_KEYDOWN
do you pass the message to eax first?

stanhebben

You can use SetCapture to capture the mouse. But then other windows won't receive mouse messages. Maybe it could be of any use?

Phoenix

Seems that there is no other way as Jackal mentioned: SetWindowsHookEx.

Link: Iczelion's Win32 Assembly Homepage Tutorial 24 - Windows Hooks: http://win32assembly.online.fr/tut24.html

Ratch

Phoenix,

Quote
Seems that there is no other way as Jackal mentioned: SetWindowsHookEx.

     No other way?  What about the method I suggested?  See reply #6 in this thread.  Ratch

Jackal

Ratch,

That should work if he sets his app to capture the mouse if i understand MSDN right.

Phoenix

Ratch,

I dont think that this will work for what Telefunken tries to do. Quote from MSDN:

QuoteThe SetCapture function sets the mouse capture to the specified window belonging to the current thread. SetCapture captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down. Only one window at a time can capture the mouse.

If the mouse cursor is over a window created by another thread, the system will direct mouse input to the specified window only if a mouse button is down.

So i think, if he wants to determine when the mouse is clicked - in our outside of the program window - he needs to work with SetWindowsHookEx. Unfortunately I have no time to give it a try........ and to see if i'm wrong. :eek

P1

For the amount of formation given, this appears to be a Focus issue.  Check out WM_ACTIVATE message, to figure is this is enough to accomplish what you what.

Now, what is it your trying to do ???  There may be a better way.

Regards,  P1  :8)

Ratch

Phoenix &  Jackal,

Quoting the MS documentation for WM_LBUTTONDOWN
Quote
The WM_LBUTTONDOWN message is posted when the user presses the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

     If he has a WinProc set up for each window, he should get those mouse click messages.  If he goes outside the client area, he should process the WM_NCLBUTTONDOWN message.  Ratch