You can use the global electron.screen
object to retrieve information about the screen(s) on the user's device, and the electron.screen.getCursorScreenPoint()
method to get the current position of the mouse pointer on the screen.
Here's an example code snippet that logs the screen position of the mouse pointer whenever the user clicks within your Electron app's main window:
const { screen } = require('electron');
// Get a reference to the main window
const mainWindow = // ...
// Attach click event listener to the main window
mainWindow.on('click', () => {
// Get the current screen cursor position
const { x, y } = screen.getCursorScreenPoint();
console.log(`Mouse pointer location: (${x}, ${y})`);
});
You can customize this code to use other input events (mousemove
, etc.) or to respond to events in specific UI elements within your app.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-03-30 11:00:00 +0000
Seen: 13 times
Last updated: Dec 09 '21
What could be the reason for the node app not functioning on Namecheap hosting?
How does rate limiting work for Azure Function in .NET 7?
What is missing since the androidmanifest.xml file is not present?
When attempting to launch my Android app, why does my AVD open YouTube instead?
How can I set up a subdomain for Apple app site association?
What is the appropriate size for App store screenshots on a 6.5" display?