2

I am learning JavaScript and in the process, I found that certain operations are not allowed in JavaScript which are fairly common in general programming. For example, it is not possible to control a user's mouse pointer in JavaScript due to obvious security reasons, see Move Mouse Cursor Javascript.

I would like to know of more such events which can be used to control user input but aren't possible in JavaScript.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
whatisinaname
  • 333
  • 4
  • 15
  • I believe your question is too broad as there will be tons of stuff left out of JavaScript that programming languages have because JavaScript is a scripting language. – Travis Pessetto Jun 29 '12 at 18:17
  • Yes, I understand. Let me rephrase the question to focus only on methods to control user events. – whatisinaname Jun 29 '12 at 18:22

2 Answers2

5

Nothing is preventing you from moving the mouse pointer from Javascript per se, it's the environment your code runs in (a web browser) that does not provide the library functions to do it.

You could work around that by writing a web browser extension (e.g. a trusted ActiveX control on Windows) that provides a binding to, say, SetCursorPos() to the scripting layer. Then you would be able to move the pointer from your Javascript code.

In other words, the Javascript language does not restrict you in any way, but a web browser environment implements (rightful) restrictions that can be lifted if you really want to (depending, of course, on the browser).

One last thing: The mouse pointer belongs to the user. Moving it programatically is intrusive, surprising, confusing, and lowers the user's confidence in your application and his desktop environment in general. Please don't do that.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • Makes sense. So, instead of focusing on Javascript, I should focus on the browsers and which events to control user inputs are allowed or which are restricted by them. And these restrictions will be different for different browsers. Correct? – whatisinaname Jun 29 '12 at 18:35
  • Correct, but remember there are very few good reasons to lift these restrictions in the first place. If you're looking for full-scale UI automation, there are [other solutions](http://msdn.microsoft.com/en-us/library/ms747327.aspx). – Frédéric Hamidi Jun 29 '12 at 18:39
  • Yes, I understand the security implications of such restrictions. That is exactly what I wanted to know i.e. what methods aren't allowed by the browsers especially to control the user input which may lead to malicious activity in certain ways. Controlling mouse pointer is one such method. – whatisinaname Jun 29 '12 at 18:44
2

Well, these might be of some help:

Here you go

Phillip Schmidt
  • 8,805
  • 3
  • 43
  • 67