Low level mouse hooк Action


#1

I saw a thread for detecting low level mouse hook events:

But can you help me please to fire this low level mouse hook with C#?


#2

Do you really need a global hook?
There was already a thread about detecting mouse events in max window. Check out my example. Maybe it is enough for your needs.


#3

Yes, I need it. I don’t know, your version works well, but if I run it more times it crashes 3ds Max at me. May be I do smth wrong… Anyway I need not to listen mouse events, but to fire low level mouse hook.

                                            windows.sendmessage certWindow WM_LBUTTONDOWN     0x0001 0 
                                            windows.sendmessage certWindow WM_LBUTTONUP       0x0001 0 
                                            windows.sendmessage certWindow WM_LBUTTONDBLCLK   0x0001 0 

ThIs is not what I need, I need only low level, but I really don’t know how to do it in c#.
I will appreciate any help.


#4

Serejah, Sorry I didnt explain which version kills max at me:

This, in fact is the only version that reads all mouse events in any window. This is what I need, the only thing is I want to fire left mouse button, I tried to do but still couldnt find a solution.


#5

What do you mean by firing mouse button?


#6

to imitate real button left click


#7

Maybe something like this will do.


#8

I want to select the node under the mouse inside Slate Material Editor, to get its coordinates.
DropingArea inside SME is not System.Windows.Forms


#9

PostMessage works ok for me. But you also need to pass mouse click position and set SME in focus before you click;

fn makeparam w l = (
		
	bit.or (bit.and w 0xFFFF) (bit.shift l 16)	

)
mouseParam = makeparam mouse.pos.x mouse.pos.y -- guess it should be relative to sme window

windows.postMessage smeViewTabHwnd 0x201 0 mouseParam
windows.postMessage smeViewTabHwnd 0x202 0 mouseParam
fn GetSMEWindowHandle = 
(	
	max_hwnd = windows.getMAXHWND()
	for m in windows.getChildrenHWND 0 where m[4] == "NodeJoeMainWindow" and m[5] == "Slate Material Editor" and m[6] == max_hwnd do exit with m[1]
	
)
sme_hwnd = GetSMEWindowHandle()
for data in windows.getChildrenHWND sme_hwnd where data[4] == "DragDropWindow" do
(
	format "%\n" data
)

#(133390P, 461030P, 461030P, “DragDropWindow”, “StatusBar”, 0P, 461030P, 461030P)
#(199100P, 461030P, 461030P, “DragDropWindow”, “”, 0P, 461030P, 461030P)
#(199034P, 199100P, 199100P, “DragDropWindow”, “View1”, 0P, 461030P, 461030P) – correct view handle
#(1247760P, 199100P, 199100P, “DragDropWindow”, “View2”, 0P, 461030P, 461030P) – correct view handle
#(199030P, 461030P, 461030P, “DragDropWindow”, “”, 0P, 461030P, 461030P)
#(199272P, 199030P, 199030P, “DragDropWindow”, “Material/Map Browser”, 461030P, 461030P, 461030P)
#(199032P, 461030P, 461030P, “DragDropWindow”, “”, 0P, 461030P, 461030P)
#(199270P, 199032P, 199032P, “DragDropWindow”, “Material Parameter Editor”, 461030P, 461030P, 461030P)
#(199576P, 199032P, 199032P, “DragDropWindow”, “Navigator”, 461030P, 461030P, 461030P)
#(199038P, 461030P, 461030P, “DragDropWindow”, “”, 0P, 461030P, 461030P)
#(199036P, 461030P, 461030P, “DragDropWindow”, “”, 0P, 461030P, 461030P)


#10

thank you Serejah, this helped!


#11
(
	fn GetSMEWindowHandle = 
	(	
		max_hwnd = windows.getMAXHWND()
		for m in windows.getChildrenHWND 0 where m[4] == "NodeJoeMainWindow" and m[5] == "Slate Material Editor" and m[6] == max_hwnd do exit with m[1]		
	)
	
	fn makeparam w l = bit.or (bit.and w 0xFFFF) (bit.shift l 16)
	
	-- todo: check that sme is active
	-- todo: check that sme has at least one tab
	
	sme_active_view_name = if SME.activeView > 0 then (SME.GetView SME.activeView).Name else undefined
	
	sme_hwnd = GetSMEWindowHandle()
	sme_view_hwnd = for data in windows.getChildrenHWND sme_hwnd where data[4] == "DragDropWindow" and data[5] == sme_active_view_name do
	(
		exit with data[1]
	)

	sme_window_pos = windows.getWindowPos sme_view_hwnd -- mxs2014+
	relative_position = [ mouse.screenpos.x - sme_window_pos.x, mouse.screenpos.y - sme_window_pos.y]

	windows.postMessage sme_view_hwnd 0x201 0 (makeparam relative_position.x relative_position.y)
	windows.postMessage sme_view_hwnd 0x202 0 (makeparam relative_position.x relative_position.y)

)

#12

Yes, this is the way I did. Thank you so much for your help )))