网站首页 首页 > 志愿填报 > 正文
js如何获取鼠标指针在元素中的坐标?
}代码如下:
获取鼠标坐标_获取鼠标坐标工具
frame.add(panel);
#canvas{
border:1px solid #ccc;
width:300px;
height:300px;
overflow:hidden;
}
function get_canvas(ev,obj){
m_clientX = ev.clientX-obj.offsetLeft;
m_clientY = ev.clientY-obj.offsetTop;
document.getElementById("tips").innerHTML = "当前坐标:X:"+ m_clientX + " ,Y:" +m_clientY;
兼容IE8+
用 jascript 获取当前页面上鼠标(光标)位置在许多情况下都会用到,比如拖放,悬停提示(tooltip) 等等。当然,这里我们依然要面对浏览器的兼容问题,在不同的浏览器下,对这些相关的属性处理方式也不同。
参考资料
c#如何获取鼠标的坐标,如何利用坐标判断鼠标是否移动
set WshShell = CreateObject("wscript.Shell")或者用钩子,不过会毒软件拦截,慎在VB中针对Form、Text文本输入框等都有关于鼠标的三个函数:,_MouseDown、_MouseMove、_MouseUp,如:关于Form有如下三个函数,只要在其中写入针对Timer控件的语句即可,无需理会坐标X、Y的值。 Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) End Sub用
如果仅获取程序内部鼠标坐标,拦截鼠标消息即可
【VBS】获取鼠标指针的坐标
private void Form1_MouseMove(object sender, MouseEventArgs e)Option Explicit
Dim WshShell
Dim oExcel, oBook, oModule
Dim strRegKey, strCode, x, y
Set oExcel = CreateObject("Excel.Application")
strRegKey '点在Y坐标(纵坐标)上的坐标值= "HKEY_CURRENT_USER\Software\Microsoft\Off\$\Excel\Security\AccessVBOM"
strRegKey = Replace(strRegKey, "$", oExcel.Version)
WshShell.RegWrite strRegKey, 1, "REG_DWORD"
Set oBook = oExcel.Workbooks.Add
Set oModule = obook.VBProject.VBComponents.Add(1)
"Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & vbCr & _
"Private Type POINTAPI : X As Long : Y As Long : End Type" & vbCr & _
"Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & vbCr & _
"Sub SetCursor(x as Long, y as Long) : SetCursorPos x, y : End Sub" & vbCr & _
"End Function" & vbCr & _
"Public Function GetYCursorPos() As Long" & vbCr & _
"Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y" & vbCr & _
"End Function"
oModule.CodeModule.AddFromString strCode
x = oExcel.Run("GetXCursorPos")
y = oExcel.Run("GetYCursorPos")
WScript.Echo x, y
oExcel.Run "SetCursor", 0, 0
oExcel.DisplayAlerts = False
oBook.Close
oExcel.Quit
VB获取鼠标在当前窗体的坐标
height:200px;TextBox1.Text = e.X.ToString
End SlayerX/Y:ub