当前位置:   article > 正文

dnf python自动搬砖定制脚本_dnf全自动搬砖脚本

dnf全自动搬砖脚本

   广告:

信号屏蔽器:守护你的数字生活,为你带来宁静与专注

https://sz-sstx.com 

恩山,修罗

驱动级键盘操作跳过检测

结合opencv简单识别图像

直接上代码

  1. import time
  2. import cv2
  3. import numpy as np
  4. import win32api
  5. import win32con
  6. import ctypes
  7. import win32gui
  8. import random
  9. import threading
  10. from PIL import Image
  11. from PIL import ImageGrab
  12. import time
  13. isEnd = False
  14. VK_CODE = {
  15. 'backspace': 0x08,
  16. 'tab': 0x09,
  17. 'clear': 0x0C,
  18. 'enter': 0x0D,
  19. 'shift': 0x10,
  20. 'ctrl': 0x11,
  21. 'alt': 0x12,
  22. 'pause': 0x13,
  23. 'caps_lock': 0x14,
  24. 'esc': 0x1B,
  25. 'spacebar': 0x20,
  26. 'page_up': 0x21,
  27. 'page_down': 0x22,
  28. 'end': 0x23,
  29. 'home': 0x24,
  30. 'left_arrow': 0x25,
  31. 'up_arrow': 0x26,
  32. 'right_arrow': 0x27,
  33. 'down_arrow': 0x28,
  34. 'select': 0x29,
  35. 'print': 0x2A,
  36. 'execute': 0x2B,
  37. 'print_screen': 0x2C,
  38. 'ins': 0x2D,
  39. 'del': 0x2E,
  40. 'help': 0x2F,
  41. '0': 0x30,
  42. '1': 0x31,
  43. '2': 0x32,
  44. '3': 0x33,
  45. '4': 0x34,
  46. '5': 0x35,
  47. '6': 0x36,
  48. '7': 0x37,
  49. '8': 0x38,
  50. '9': 0x39,
  51. 'a': 0x41,
  52. 'b': 0x42,
  53. 'c': 0x43,
  54. 'd': 0x44,
  55. 'e': 0x45,
  56. 'f': 0x46,
  57. 'g': 0x47,
  58. 'h': 0x48,
  59. 'i': 0x49,
  60. 'j': 0x4A,
  61. 'k': 0x4B,
  62. 'l': 0x4C,
  63. 'm': 0x4D,
  64. 'n': 0x4E,
  65. 'o': 0x4F,
  66. 'p': 0x50,
  67. 'q': 0x51,
  68. 'r': 0x52,
  69. 's': 0x53,
  70. 't': 0x54,
  71. 'u': 0x55,
  72. 'v': 0x56,
  73. 'w': 0x57,
  74. 'x': 0x58,
  75. 'y': 0x59,
  76. 'z': 0x5A,
  77. 'numpad_0': 0x60,
  78. 'numpad_1': 0x61,
  79. 'numpad_2': 0x62,
  80. 'numpad_3': 0x63,
  81. 'numpad_4': 0x64,
  82. 'numpad_5': 0x65,
  83. 'numpad_6': 0x66,
  84. 'numpad_7': 0x67,
  85. 'numpad_8': 0x68,
  86. 'numpad_9': 0x69,
  87. 'multiply_key': 0x6A,
  88. 'add_key': 0x6B,
  89. 'separator_key': 0x6C,
  90. 'subtract_key': 0x6D,
  91. 'decimal_key': 0x6E,
  92. 'divide_key': 0x6F,
  93. 'F1': 0x70,
  94. 'F2': 0x71,
  95. 'F3': 0x72,
  96. 'F4': 0x73,
  97. 'F5': 0x74,
  98. 'F6': 0x75,
  99. 'F7': 0x76,
  100. 'F8': 0x77,
  101. 'F9': 0x78,
  102. 'F10': 0x79,
  103. 'F11': 0x7A,
  104. 'F12': 0x7B,
  105. 'F13': 0x7C,
  106. 'F14': 0x7D,
  107. 'F15': 0x7E,
  108. 'F16': 0x7F,
  109. 'F17': 0x80,
  110. 'F18': 0x81,
  111. 'F19': 0x82,
  112. 'F20': 0x83,
  113. 'F21': 0x84,
  114. 'F22': 0x85,
  115. 'F23': 0x86,
  116. 'F24': 0x87,
  117. 'num_lock': 0x90,
  118. 'scroll_lock': 0x91,
  119. 'left_shift': 0xA0,
  120. 'right_shift ': 0xA1,
  121. 'left_control': 0xA2,
  122. 'right_control': 0xA3,
  123. 'left_menu': 0xA4,
  124. 'right_menu': 0xA5,
  125. 'browser_back': 0xA6,
  126. 'browser_forward': 0xA7,
  127. 'browser_refresh': 0xA8,
  128. 'browser_stop': 0xA9,
  129. 'browser_search': 0xAA,
  130. 'browser_favorites': 0xAB,
  131. 'browser_start_and_home': 0xAC,
  132. 'volume_mute': 0xAD,
  133. 'volume_Down': 0xAE,
  134. 'volume_up': 0xAF,
  135. 'next_track': 0xB0,
  136. 'previous_track': 0xB1,
  137. 'stop_media': 0xB2,
  138. 'play/pause_media': 0xB3,
  139. 'start_mail': 0xB4,
  140. 'select_media': 0xB5,
  141. 'start_application_1': 0xB6,
  142. 'start_application_2': 0xB7,
  143. 'attn_key': 0xF6,
  144. 'crsel_key': 0xF7,
  145. 'exsel_key': 0xF8,
  146. 'play_key': 0xFA,
  147. 'zoom_key': 0xFB,
  148. 'clear_key': 0xFE,
  149. '+': 0xBB,
  150. ',': 0xBC,
  151. '-': 0xBD,
  152. '.': 0xBE,
  153. '/': 0xBF,
  154. ' ': 0xBA,
  155. '[': 0xDB,
  156. '\\': 0xDC,
  157. ']': 0xDD,
  158. "'": 0xDE,
  159. '`': 0xC0}
  160. # handle = win32gui.FindWindow(None, '地下城与勇士')
  161. # win32gui.SetForegroundWindow(handle)
  162. # 获取随机时间上下0.1倍浮动
  163. def getRandomTime(t):
  164. t0 = t - t * 0.01
  165. t2 = t + t * 0.01
  166. # print("左边界",t0)
  167. # print("有边界",t2)
  168. t1 = random.uniform(t0, t2)
  169. # print("随机结果",t1)
  170. return t1
  171. # 等待操作
  172. def sleep(t):
  173. time.sleep(getRandomTime(t))
  174. # 按键操作(按一次松)
  175. def keyOperation(button, t):
  176. win32api.keybd_event(VK_CODE[button], win32api.MapVirtualKey(VK_CODE[button], 0), 0, 0) # 0
  177. t = getRandomTime(t)
  178. sleep(t)
  179. win32api.keybd_event(VK_CODE[button], win32api.MapVirtualKey(VK_CODE[button], 0), win32con.KEYEVENTF_KEYUP, 0)
  180. sleep(0.1)
  181. # 加破击兵刃
  182. # 按下某个键
  183. def keyOn(button):
  184. win32api.keybd_event(VK_CODE[button], win32api.MapVirtualKey(VK_CODE[button], 0), 0, 0) # 0
  185. def keyOf(button):
  186. win32api.keybd_event(VK_CODE[button], win32api.MapVirtualKey(VK_CODE[button], 0), win32con.KEYEVENTF_KEYUP, 0)
  187. def getbuff1():
  188. keyOperation("q",0.4)
  189. # 加流行狂
  190. def getbuff2():
  191. keyOperation("d", 0.05)
  192. keyOperation("d", 0.1)
  193. keyOperation("j", 0.1)
  194. # 流星升+
  195. def liuxingsheng():
  196. keyOperation("o", 0.1)
  197. keyOperation("l", 0.2)
  198. sleep(0.5)
  199. keyOperation("o", 0.2)
  200. # 里鬼剑术
  201. def ligui():
  202. i = 0
  203. while True:
  204. i = i + 1
  205. if (i == 3):
  206. return
  207. keyOperation("u", 0.05)
  208. keyOperation("u", 0.05)
  209. keyOperation("u", 0.05)
  210. keyOperation("o", 0.05)
  211. keyOperation("o", 0.05)
  212. sleep(1)
  213. # 前冲
  214. def go(t):
  215. keyOperation("d", 0.1)
  216. keyOperation("d", t)
  217. # 进入房间的操作d
  218. def intoRoom():
  219. go(getRandomTime(2))
  220. keyOperation("f", 0.1)
  221. go(getRandomTime(2))
  222. # 测试用
  223. # 猛龙
  224. def menglong():
  225. keyOn("d")
  226. keyOperation("p", 0.1)
  227. keyOf("d")
  228. keyOn("a")
  229. keyOperation("p", 0.5)
  230. keyOf("a")
  231. # 是否有闪光
  232. def has_gold_flash(image):
  233. # 加载图像并转换为RGB模式
  234. image = image.convert('RGB')
  235. # image = Image.open(image_path).convert('RGB')
  236. # 获取图像的宽度和高度
  237. width, height = image.size
  238. # 遍历图像的每个像素
  239. for x in range(width):
  240. for y in range(height):
  241. # 获取当前像素的颜色
  242. r, g, b = image.getpixel((x, y))
  243. # 检查当前像素是否为金色
  244. if r > g and r > b and g < b:
  245. return True
  246. # 如果没有找到金色闪光,返回False
  247. return False
  248. def gran_screen_pil():
  249. # 截取窗口图片,建议将游戏窗口调整到最左上角,调整后面两个参数截取你想要的图片大小
  250. image = ImageGrab.grab(bbox=(0, 0, 1350, 760))
  251. image = np.array(image)
  252. end = cv2.imread('D:\desktop\dnf\end.png', cv2.IMREAD_GRAYSCALE)
  253. if len(image.shape) > 2:
  254. image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  255. if len(end.shape) > 2:
  256. end = cv2.cvtColor(end, cv2.COLOR_BGR2GRAY)
  257. resultEnd = cv2.matchTemplate(image, end, cv2.TM_SQDIFF_NORMED)
  258. minEnd_val, maxEnd_val, minEnd_loc, maxEnd_loc = cv2.minMaxLoc(resultEnd)
  259. # print('结果{}----------------{}',minEnd_val,maxEnd_val)
  260. if (minEnd_val < 0.5):
  261. global isEnd
  262. print("见到结束画面,开始下一把")
  263. isEnd = True
  264. # if has_gold_flash(image):
  265. # print("有金色闪光")
  266. def ci():
  267. keyOperation("d", 0.1)
  268. keyOn("d")
  269. sleep(0.2)
  270. keyOperation("j", 0.05)
  271. keyOperation("j", 0.05)
  272. keyOf("d")
  273. def read_picture():
  274. while True:
  275. # 1秒后开始截图hd
  276. time.sleep(0.1)
  277. gran_screen_pil()
  278. def do():
  279. global isEnd
  280. while True:
  281. isEnd = False
  282. print("开始!")
  283. getbuff2()
  284. sleep(1)
  285. print('杀意buff!')
  286. getbuff1()
  287. print("波动刻印!")
  288. time.sleep(0.5)
  289. go(5)
  290. keyOperation("h", 1)
  291. sleep(1.5)
  292. print("第一个图打完")
  293. go(2.3)
  294. keyOperation("f", 0.2)
  295. sleep(getRandomTime(1.5))
  296. print("第2个图打完")
  297. # keyOperation("o",0.2)
  298. # sleep(1)
  299. go(1.3)
  300. keyOperation("u",0.2)
  301. print("邪光斩!")
  302. sleep(0.5)
  303. keyOperation("p", 0.2)
  304. sleep(1)
  305. go(3.7)
  306. keyOperation("y",0.2)
  307. print("y技能")
  308. sleep(3)
  309. go(2)
  310. # keyOperation("n",0.2)
  311. # print("二觉")
  312. # sleep(2)
  313. keyOperation("e",0.2)
  314. sleep(0.5)
  315. keyOperation("t", 0.2)
  316. print("三觉")
  317. sleep(6.2)
  318. if(isEnd):
  319. print("结束")
  320. doEnd()
  321. continue
  322. keyOperation("b",0.2)
  323. if(isEnd):
  324. print("结束")
  325. doEnd()
  326. continue
  327. if(isEnd):
  328. print("结束")
  329. doEnd()
  330. continue
  331. sleep(1)
  332. keyOperation("h",0.2)
  333. sleep(1)
  334. keyOperation("q",0.2)
  335. print("q技能")
  336. sleep(3)
  337. if(isEnd):
  338. print("结束")
  339. doEnd()
  340. continue
  341. keyOperation("h",0.2)
  342. print("圣又之阵")
  343. sleep(1)
  344. if(isEnd):
  345. print("结束")
  346. doEnd()
  347. continue
  348. doEnd()
  349. # 最后一个图的结束操作n
  350. def doEnd():
  351. print("结束")
  352. keyOperation("0", 0.2)
  353. keyOperation("j", 0.2)
  354. keyOperation("j", 0.2)
  355. keyOperation("j", 0.2)
  356. keyOperation("j", 0.2)
  357. keyOperation("j", 0.2)
  358. keyOperation("j", 0.2)
  359. keyOperation("j", 0.2)
  360. keyOperation("j", 0.2)
  361. keyOperation("j", 0.2)
  362. keyOperation("j", 0.2)
  363. keyOperation("j", 0.2)
  364. keyOperation("j", 0.2)
  365. keyOperation("j", 0.2)
  366. time.sleep(0.5)
  367. keyOperation("esc", 0.2)
  368. time.sleep(0.5)
  369. keyOperation("F10", 0.2)
  370. time.sleep(4)
  371. if __name__ == '__main__':
  372. sleep(2)
  373. t1 = threading.Thread(target=read_picture)
  374. t2 = threading.Thread(target=do)
  375. t1.start()
  376. t2.start()

注意,需要以管理员身份运行代码即可

更多细节请咨询sz-sstx.com留言                                                        

                                                                                                                                源自sz-sstx.com

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/688132
推荐阅读
相关标签
  

闽ICP备14008679号