這篇文章將為大家詳細(xì)講解有關(guān)在python中怎么用ctypes模擬點(diǎn)擊,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括馬邊彝族網(wǎng)站建設(shè)、馬邊彝族網(wǎng)站制作、馬邊彝族網(wǎng)頁(yè)制作以及馬邊彝族網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃等。多年來(lái),我們專(zhuān)注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,馬邊彝族網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到馬邊彝族省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
按鍵精靈提供的窗口api性能并不算的上太好。但是將整個(gè)邏輯搬到python上,并提供了自己所寫(xiě)的api后,速度有了很大的提升。
直接用python調(diào)用,獲取特定點(diǎn)位置上的顏色,非白色就發(fā)送點(diǎn)擊指令。然后循環(huán)等待下一個(gè)黑色塊的到來(lái)。同時(shí)設(shè)定定時(shí)時(shí)間,若長(zhǎng)時(shí)間依舊是這個(gè)顏色,證明游戲結(jié)束,直接退出。代碼如下:
WindowFunction = ctypes.windll.LoadLibrary("E:\\Python Hack\\DLL\\ScreenFunction.dll") DllGetPixel = WindowFunction.GetWindowPixel DllGetPixel.argtypes=[ctypes.wintypes.HWND,ctypes.wintypes.c_int,ctypes.wintypes.c_int] DllGetPixel.restypes=[ctypes.wintypes.c_uint32] DllGetMultiPixel = WindowFunction.GetWindowMultiPixel DllGetMultiPixel.argtypes=[ctypes.wintypes.HWND,ctypes.wintypes.c_void_p,ctypes.wintypes.c_void_p] DllGetMultiPixel.restypes=[ctypes.wintypes.c_int] cMulti = (ctypes.wintypes.c_int * 17)(Pos0.x,Pos0.y,Pos1.x,Pos1.y,Pos2.x,Pos2.y,Pos3.x,Pos3.y, Pos0.x,Pos0.y-5,Pos1.x,Pos1.y-5,Pos2.x,Pos2.y-5,Pos3.x,Pos3.y-5, 0) dwLen = DllGetMultiPixel(wHWND,byref(cMulti),None) RGB = (ctypes.wintypes.DWORD * dwLen)() quit = False while not quit: DllGetMultiPixel(wHWND,byref(cMulti),byref(RGB)) flag = 0 if not RGB[0] == 0xfff5f5f5 or not RGB[4] == 0xfff5f5f5: EmuCursorClick(rect.left+Pos0.x,rect.top+Pos0.y) flag = 1 elif not RGB[1] == 0xfff5f5f5 or not RGB[5] == 0xfff5f5f5: EmuCursorClick(rect.left+Pos1.x,rect.top+Pos1.y) flag = 2 elif not RGB[2] == 0xfff5f5f5 or not RGB[6] == 0xfff5f5f5: EmuCursorClick(rect.left+Pos2.x,rect.top+Pos2.y) flag = 3 elif not RGB[3] == 0xfff5f5f5 or not RGB[7] == 0xfff5f5f5: EmuCursorClick(rect.left+Pos3.x,rect.top+Pos3.y) flag = 4 cot = 0 if flag == 0: quit=True elif flag == 1: RGB0 = DllGetPixel(wHWND,Pos0.x,Pos0.y) & 0xffffffff while not RGB0 == 0xfff5f5f5: time.sleep(0.05) cot += 1 if cot > 20: quit=True break RGB0 = DllGetPixel(wHWND,Pos0.x,Pos0.y) & 0xffffffff elif flag == 2: RGB1 = DllGetPixel(wHWND,Pos1.x,Pos1.y) & 0xffffffff while not RGB1 == 0xfff5f5f5: time.sleep(0.05) cot += 1 if cot > 20: quit=True break RGB1 = DllGetPixel(wHWND,Pos1.x,Pos1.y) & 0xffffffff elif flag == 3: RGB2 = DllGetPixel(wHWND,Pos2.x,Pos2.y) & 0xffffffff while not RGB2 == 0xfff5f5f5: time.sleep(0.05) cot += 1 if cot > 20: quit=True break RGB2 = DllGetPixel(wHWND,Pos2.x,Pos2.y) & 0xffffffff elif flag == 4: RGB3 = DllGetPixel(wHWND,Pos3.x,Pos3.y) & 0xffffffff while not RGB3 == 0xfff5f5f5: time.sleep(0.05) cot += 1 if cot > 20: quit=True break RGB3 = DllGetPixel(wHWND,Pos3.x,Pos3.y) & 0xffffffff print 'end'
關(guān)于在python中怎么用ctypes模擬點(diǎn)擊就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。