例如,我正在使用使用滑鼠驅動程式發送滑鼠輸入的專案
from ctypes import *
import time
dd_dll = windll.LoadLibrary('x:\DD94687.64.dll')
time.sleep(2)
st = dd_dll.DD_btn(0) #DD Initialize
if st==1:
print("OK")
else:
print("Error")
exit(101)
#Second argument = positive numbers moves the mouse down, Negative numbers moves the mouse up
#First argument = positive numbers moves the mouse right, negative numbers moves the mouse left
#This will move the curser 5 pixels to the right, and 10 pixels down
def dd_dll.DD_movR(5,10)
可以在這里找到,我想計算游標增量并將其從螢屏中心(起點)按增量(每個具體為 5 個像素)移動到用戶指定的另一個點(它可以是螢屏上的任何坐標) .
我正在使用該DD_movR()功能,還有另一個功能是DD_mov()將游標移動到指定X,Y位置,但由于某種原因,它會放大0.25. 所以如果我想將游標移動到(625,625)我的輸入應該是(500,500). 只要我按增量移動滑鼠而不是跳轉指定位置,我就想使用它們中的任何一個。我知道還有其他方法/庫可以執行相同的功能,但是目標 iam 將滑鼠輸入發送到所有這些塊,我發現這是可行的。
uj5u.com熱心網友回復:
因此,您要確定將游標移動到的下一個位置。
讓我們想象一下,我們有一條連接源點和目標點的直線(在您的特定問題中,源點是螢屏的中間,但選擇哪個點作為起點并不重要)。游標的下一個位置應與該行大致對齊;并且,它的 x 位置應該與前一個點相差 5 個像素。
因此,計算下一個點的 x 位置是相當清楚的。現在你應該利用另一個想法(下一個點與直線對齊)來計算它的 y 位置。你應該怎么做?
要使用直線,您必須知道它是什么:事實證明,從源點和目標點推匯出該直線的方程是微不足道的。可以參考這篇文章https://www.mathsisfun.com/algebra/line-equation-2points.html
請注意,您已經有了 x 位置。只需將其插入該線方程,您將獲得 y 位置(下限為整數)。那將是下一個 y 位置。
計算下一個點的位置后,如果要使用DD_movR,只需進行減法即可找到下一個點與前一個點之間的差異。
此外,您應該檢查一個極端情況:當下一個點超過目標點時。要解決此問題,您可以丟棄計算的下一個點并使用目標點。您的游標移動程序也應該在這里結束。
這是上述想法的 Python 代碼。還有一些特殊情況需要處理。
#source = (x1, y1) : the current position of the cursor
#destination = (x2, y2): the position we want to move the cursor to at the end
def nextX(x1, x2):
if (x2 >= x1 5):
return x1 5
elif (x2 >= x1):
return x2
elif (x2 < x1 - 5):
return x1 - 5
else:
return x2
def slope(x1, y1, x2, y2):
return (y2 - y1) / (x2 - x1) #TODO: need to handle corner case where x1 == x2
#equation will be y - y1 = slope * (x - x1)
#or equivalently y = slope * x y1 - slope * x1
def nextY(x1, y1, x2, y2):
eqSlope = slope(x1, y1, x2, y2)
y = eqSlope * nextX(x1, x2) y1 - eqSlope * x1
return round(y)
def move(x1, y1, x2, y2):
nextPosX = nextX(x1, x2)
nextPosY = nextY(x1, y1, x2, y2)
dd_dll.DD_movR(nextPosX - x1, nextPosY - y1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/477030.html
上一篇:填充線性模型中的缺失資料
