JavaScript: Check if mouse button down?

Regarding Pax’ solution: it doesn’t work if user clicks more than one button intentionally or accidentally. Don’t ask me how I know :-(. The correct code should be like that: var mouseDown = 0; document.body.onmousedown = function() { ++mouseDown; } document.body.onmouseup = function() { –mouseDown; } With the test like this: if(mouseDown){ // crikey! isn’t … Read more

Which is the easiest way to simulate keyboard and mouse on Python?

I do automated testing stuff in Python. I tend to use the following: http://www.tizmoi.net/watsup/intro.html Edit: Link is dead, archived version: https://web.archive.org/web/20100224025508/http://www.tizmoi.net/watsup/intro.html http://www.mayukhbose.com/python/IEC/index.php I do not always (almost never) simulate key presses and mouse movement. I usually use COM to set values of windows objects and call their .click() methods. You can send keypress signals with … Read more

Determine which element the mouse pointer is on top of in JavaScript

DEMO There’s a really cool function called document.elementFromPoint which does what it sounds like. What we need is to find the x and y coords of the mouse and then call it using those values: document.addEventListener(‘mousemove’, e => { console.clear() console.log( document.elementFromPoint(e.clientX, e.clientY) ) }, {passive: true}) [class^=’level’]{ width: 100px; height: 100px; padding: 15px; background: … Read more

Wanting a type of grid for a pixel editor

More than a few hundred components is awkward. One easy way to get big pixels is to use drawImage() and scale the mouse coordinates as shown here and here. Here’s a simple example. import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.awt.image.BufferedImage; import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JPanel; … Read more

Move the mouse pointer to a specific position?

You cannot move the mousepointer with javascript. Just think about the implications for a second, if you could 😉 User thinks: “hey I’d like to click this link” Javascript moves mousecursor to another link User clicks wrong link and inadvertently downloads malware that formats his c-drive and eats his candy