JavaScript simulate right click through code

try this instead, reason what things didn’t quite work is that the context menu is in fact bound to the oncontextmenu event. function contextMenuClick(element){ var evt = element.ownerDocument.createEvent(‘MouseEvents’); var RIGHT_CLICK_BUTTON_CODE = 2; // the same for FF and IE evt.initMouseEvent(‘contextmenu’, true, true, element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, RIGHT_CLICK_BUTTON_CODE, null); if … Read more

Simulating a mousedown, click, mouseup sequence in Tampermonkey?

Send mouse events. Like so: //— Get the first link that has “stackoverflow” in its URL. var targetNode = document.querySelector (“a[href*=’stackoverflow’]”); if (targetNode) { //— Simulate a natural mouse-click sequence. triggerMouseEvent (targetNode, “mouseover”); triggerMouseEvent (targetNode, “mousedown”); triggerMouseEvent (targetNode, “mouseup”); triggerMouseEvent (targetNode, “click”); } else console.log (“*** Target node not found!”); function triggerMouseEvent (node, eventType) { … Read more

Delay jquery hover event?

Use the hoverIntent plugin for jquery: http://cherne.net/brian/resources/jquery.hoverIntent.html It’s absolutely perfect for what you describe and I’ve used it on nearly every project that required mouseover activation of menus etc… There is one gotcha to this approach, some interfaces are devoid of a ‘hover’ state eg. mobile browsers like safari on the iphone. You may be … Read more

Pass-through mouse events to parent control

Yes. After a lot of searching, I found the article “Floating Controls, tooltip-style”, which uses WndProc to change the message from WM_NCHITTEST to HTTRANSPARENT, making the Control transparent to mouse events. To achieve that, create a control inherited from Label and simply add the following code. protected override void WndProc(ref Message m) { const int … Read more

Global mouse event handler

return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0); This code will fail when you run it on .NET 4 on a Windows version earlier than Windows 8. The CLR no longer simulates unmanaged module handles for managed assemblies. You can’t detect this failure in your code because it is missing the required error checking. Both on GetModuleHandle and … Read more

jQuery get mouse position within an element

One way is to use the jQuery offset method to translate the event.pageX and event.pageY coordinates from the event into a mouse position relative to the parent. Here’s an example for future reference: $(“#something”).click(function(e){ var parentOffset = $(this).parent().offset(); //or $(this).offset(); if you really just want the current element’s offset var relX = e.pageX – parentOffset.left; … Read more