mouse

Java getting mouse location on multiple monitor environment

妖精的绣舞 提交于 2019-11-28 12:48:32
I have searched for a while on the internet but I didn't find any solution for my problem. I know that you can get the current mouse position with PointerInfo a = MouseInfo.getPointerInfo(); Point b = a.getLocation(); The problem is in a multi environment screen I am just getting the mouse position relative to the main screen. Which means if the second screen is to the left of the main screen I receive for example X: -917.0 Location Y: -137.0. I know that these values depend on the screen resolution and the order of the monitors. Is there any possibility to obtain the mouse position on the

Java Swing: change background color on mouse over

家住魔仙堡 提交于 2019-11-28 12:34:14
I've implemented a simple mouse listener where the background color changes whenever the mouse enters the component (a JPanel), and it reverts back whenever the mouse leaves. This has some problems: Sometimes the mouse moves so quick that the mouseExit event is not fired If my component has childs, when the mouse moves to the childs it triggers the mouseExit If I move the mouse over to the childs quickly, the mouseEnter event is not fired I'm guessing this is an easy one for Swing veterans. Any suggestions on how to fix this? I'd love not to use timers and such... If I move the mouse over to

Zooming To Mouse Point With ScrollView and ViewBox in Wpf

爱⌒轻易说出口 提交于 2019-11-28 11:40:23
I have some paths drawn to the screen in wpf. The coordinates being used are quite small so they have been made to fill the screen with a view box. I am now trying to implement pan and zoom functionality. I would like to be able to zoom to wherever the mouse is in relation to the ui (i.e zoomed screen center is equal to mouse coordinates). The current outcome is that the center of the screen when zoomed is not reflective of the exact mouse position on the ui. If you want to see what is happening... Here is my current solution file . Or Heres some code: View Xaml <Grid Name="MasterGrid"

HTML5 Canvas moving object to mouse click position

馋奶兔 提交于 2019-11-28 11:37:03
Basically I want to move an object from point A ( 10x,10y ) to a position on the canvas where the mouse has been clicked ( 255x,34y ). I'm currently using a method, but it goes from ++X then ++Y to coordinates; up then right. I want it to go straight to position, likes an animation on a path. Slowing going from point A to Point B. When you “move” an object, what you really need to do is erase the object and redraw it First code a function that will redraw the rect at a specified x,y function draw(x,y){ ctx.clearRect(0,0,canvas.width,canvas.height); ctx.beginPath(); ctx.fillStyle="skyblue"; ctx

How can I get the mouse position in a console program?

拜拜、爱过 提交于 2019-11-28 11:18:14
How can I get the mouse click position in C++ in a Windows console program? (A variable that returns the position of the mouse when clicked) I want to draw a menu with simple text commands, so when someone clicks, the game will register it and know the position. I know how to do everything I need to do except get the mouse position when clicked. You'll need to use the *ConsoleInput family of methods (peek, read, etc). These operate on the console's input buffer, which includes keyboard and mouse events . The general strategy is: wait on the console's input buffer handle ( ReadConsoleInput )

Print while mouse pressed

此生再无相见时 提交于 2019-11-28 10:17:00
问题 i am using PyMouse(Event) for detecting if mouse button is pressed: from pymouse import PyMouseEvent class DetectMouseClick(PyMouseEvent): def __init__(self): PyMouseEvent.__init__(self) def click(self, x, y, button, press): if button == 1: if press: print("click") else: self.stop() O = DetectMouseClick() O.run() This works so far, but now i want to loop print("click") until mouse isnt pressed anymore ... i tried: def click(self, x, y, button, press): if button == 1: if press: do = 1 while do

Scroll JScrollPane by dragging mouse (Java swing)

社会主义新天地 提交于 2019-11-28 09:23:46
I am making a map editor for a game I am working on. There is a JPanel in the JScrollPane that displays the map to be edited. What I would like to do is make it that when the user is holding down the Spacebar and dragging their mouse in the JPanel, the JScrollPanel will scroll along with the dragging. Here is what I have so far: panelMapPanel.addMouseMotionListener(new MouseMotionListener(){ @Override public void mouseDragged(MouseEvent e) { //Gets difference in distance x and y from last time this listener was called int deltaX = mouseX - e.getX(); int deltaY = mouseY - e.getY(); mouseX = e

Preventing opera mouse gestures

僤鯓⒐⒋嵵緔 提交于 2019-11-28 09:23:24
问题 Is it possible to prevent opera mouse gestures for right button? I have web app on html5 and I decided to use right mouse button. But it doesnt work in opera, because opera has mouse gestures. event.preventDefault(); // it doesn't work May be anybody knows? Thank you. 回答1: It doesn't actually have anything to do with gestures specifically. Opera doesn't allow scripts to detect context menu events by default so you'd have to ask users to change their site preferences for your site to allow

win32: simulate a click without simulating mouse movement?

独自空忆成欢 提交于 2019-11-28 09:14:10
I'm trying to simulate a mouse click on a window. I currently have success doing this as follows (I'm using Python, but it should apply to general win32): win32api.SetCursorPos((x,y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0) This works fine. However, if the click happens while I'm moving the mouse manually, the cursor position gets thrown off. Is there any way to send a click directly to a given (x,y) coordinate without moving the mouse there? I've tried something like the following with not much luck: nx = x*65535/win32api

Which mouse button is the middle one?

和自甴很熟 提交于 2019-11-28 08:59:30
I'm currently developing a program in Java where a certain event must be triggered only when the user clicks with both the left and the right click on a button. Since it is a little unconventional, I decided to first test this. Here it is: import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JLabel; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; public class GUI { private JFrame mainframe; private JButton thebutton; private boolean left_is_pressed; private boolean right_is_pressed; private JLabel notifier; public GUI () { thebutton = new JButton (