api取鼠标坐标点?获取鼠标点击时的坐标
一、api***易语言***获取鼠标点击时的坐标
.版本2
.支持库EdirectX
.子程序__启动窗口_创建完毕
输入设备1.选择输入设备(真,假,假)
输入设备1.置刷新时间(50)
输入设备1.初始化(0)
.子程序_输入设备1_鼠标按键被改变
.参数键值,整数型
.参数键状态,整数型
.局部变量x,整数型
.局部变量y,整数型
x=取鼠标水平位置()
y=取鼠标垂直位置()
_启动窗口.标题=“X坐标”+到文本(x)+“”+“X坐标”+到文本(y)
不懂加QQ344799981
二、C程序中,怎样获得鼠标的坐标
想要获取鼠标坐标并不容易,还是一样需要调用两个API函数GetCursorPos()获取鼠标指针位置(屏幕坐标)然后采用ScreenToClient()将鼠标指针位置转换为窗口坐标输出即可。上例子。
//程序名称:通过 API获取鼠标状态
//
#include<graphics.h>
#include<stdio.h>
void main()
{
initgraph(640, 480);//初始化绘图窗口
HWND hwnd= GetHWnd();//获取绘图窗口句柄
POINT point;
TCHAR s[10];
while(true)
{
GetCursorPos(&point);//获取鼠标指针位置(屏幕坐标)
ScreenToClient(hwnd,&point);//将鼠标指针位置转换为窗口坐标
//获取鼠标按键状态可以用 GetAsyncKeyState函数,这里不再详述。
//输出鼠标坐标
sprintf(s, _T("%05d"), point.x);
outtextxy(0, 0, s);
sprintf(s, _T("%05d"), point.y);
outtextxy(0, 20, s);
//适当延时
Sleep(10);
}
}
同样运行环境需要安装EasyX。
三、如何获取鼠标在我定义的坐标系的坐标(vb)
Private Type POINTAPI'定义坐标的类型
X As Long
Y As Long
End Type
Private Declare Function ScreenToClient Lib"user32"(ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib"user32"(lpPoint As POINTAPI) As Long
'5480.88 3472.43
Private Sub Form_Load()
Dim I As Double
Dim J As Double
Me.Height= 12330
Me.Width= 14865
Me.Scale(398924.16, 4323446.22)-(404405.04, 4319973.79)'自定义坐标系
For I= 399617.646 To 404405.04 Step 1097.376'画网格线
CurrentX= I'标注
CurrentY= 4319973.79+ 100
Print CStr(I)
Me.Line(I, 4319973.79)-(I, 4323446.22)
Next
For J= 4322752.734 To 4320667.276 Step-693.486
CurrentX= 398520.27+ 400
CurrentY= J- 50
Print J
Me.Line(398520.27, J)-(404405.04, J)
Next
Me.PSet(401114.912, 4321362.762), vbRed'测试它与label1 label2的值是否相差很大
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MousePS As POINTAPI
'Dim ps As POINTAPI
GetCursorPos MousePS'获取鼠标在屏幕的位置
ScreenToClient Me.hwnd, MousePS'把鼠标的屏幕位置换成窗口位置
'*********************************************************
'***算式(1)(2)是把窗口坐标换成自定义的坐标
'***点(398924.16, 4323446.22)为自定义坐标系在窗口的顶点
'***982 791为窗口坐标时坐标的大值
'***5480.88 3472.43为自定义坐标 X Y方向上的大差值
'*********************************************************
Label1= 398924.16+(MousePS.X/ 982)* 5480.88'算式(1)
Label2= 4319973.79+(791- MousePS.Y)/ 791* 3742.43'算式(2)
End Sub
四、input组件中框获取鼠标右击坐标并插入文本
<template>
<div>
<el-input
v-model="value"
placeholder="请输入..."
style="width: 300px;"
ref="commonDivContent"
@contextmenu.native="openMenu($event)"
//组件api失焦**
@on-blur= "blurEvent($event)"
></el-input>
<div
v-if="menuFlag"
ref="commonMouseRightMenu"
:id="rightMenuId"
class="hws-right-menu"
:style="style"
>
<!-- <div class="hws-copy" v-if="copyData && isNeedCopyContent">
<div class="hws-copy-title">剪切板</div>
<div class="hws-copy-content" @click="insert(copyData)">{{copyData}}</div>
</div> -->
<ul>
<li
v-for="item in list"
:key="item.id || item.value"
:ref="item.id || item.value"
@click="insert(item.value)"
>
<span>{{ item.name }}</span>
</li>
</ul>
</div>
</div>
</template>
<script>
export default {
components: {CommonMouseMenu},
data() {
return {
templateParamData: 'fsdfhaksdjhf',
list: [
{
name: '插入年份<yyyy>(如2009)',
value: '<yyyy>'
},
{
name: '插入年份<yy>(如09)',
value: '<yy>'
},
{
name: '插入月份<mm>(如02)',
value: '<mm>'
},
{
name: '插入月份<fmmm>(如2)',
value: '<fmmm>'
},
{
name: '插入日<dd>(如05日)',
value: '<dd>'
},
{
name: '插入日<fmdd>(如5日)',
value: '<fmdd>'
}
],
menuFlag: false,
value: '你今天也超级棒',
style: {
left: 0,
top: 0
},
rightMenuRange: {},
//失焦之后记录坐标位置值
blurIndex: null
}
},
computed: {
rightMenuId() {
return 'rightMenuId-' + this.id
}
},
methods: {
openMenu(e) {
e.preventDefault()
// console.log(e)
this.menuFlag = true
// this.menuFlag = true
// // 当前浏览器窗口宽度跟高度
const clientWidth = document.body.clientWidth
const clientHeight = document.body.clientHeight
// // 打开右键菜单
this.$nextTick(() => {
const commonMouseRightMenu = document.getElementById(this.rightMenuId)
const rightMenuWidth = commonMouseRightMenu.offsetWidth || 210
// // 鼠标点的坐标
// clientX **属性返回当**被触发时鼠标指针相对于浏览器页面(或客户区)的水平坐标
const oX = e.clientX + rightMenuWidth > clientWidth ? e.clientX - rightMenuWidth : e.clientX
const oY = e.clientY + 200 > clientHeight ? e.clientY - 100 : e.clientY
// let el = this.$ref**onDivContent
// console.log(el)
// 记录鼠标光标的位置
this.rightMenuRange = window.getSelection().getRangeAt(0)
// 右键菜单出现后的位置
this.style.left = oX + 'px'
this.style.top = oY + 'px'
})
},
// 鼠标插入数据*作
insert(text) {
this.$nextTick(() => {
let str = this.value.toString()
this.value = str.slice(0, this.blurIndex) + text + str.slice(this.blurIndex)
})
},
blurEvent(e) {
this.blurIndex = e.srcElement.selectionStart
}
}
}
</script>
<style lang="scss" scoped>
.hws-right-menu {
position: fixed;
left: 0;
top: 0;
height: auto;
max-height: 200px;
min-width: 210px;
background-color: white;
box-shadow: 2px 5px 6px #c2c1c2;
display: block;
border-radius: 2px;
overflow-y: auto;
border: 1px solid lightgrey;
}
</style>