How to use keypress method in pyatom

Best Python code snippet using pyatom_python

playerKeys.py

Source:playerKeys.py Github

copy

Full Screen

1'''2Created on 10 Apr. 20183@author: bob4'''5import pygame6from bomb import *7def playerKeys(keypress, myboard, players, bombs):8 9 for each in players:10 if each.itemDeploy != 0:11 each.itemDeploy -= 112 13 14 p1Direction = [0,0] # tracking player direction for items hammer etc15 p2Direction = [0,0]16 p3Direction = [0,0]17 p4Direction = [0,0]18 19 #player 1 keys20 # for player 1 movement21 for each in players:22 if each.itemDeploy != 0:23 each.itemDeploy -= 124 25 26 p1Direction = [0,0] # tracking player direction for items hammer etc27 28 if keypress[pygame.K_UP]:29 players[0].moveUp(myboard) 30 p1Direction[1] -= 131 if keypress[pygame.K_DOWN]:32 players[0].moveDown(myboard)33 p1Direction[1] += 134 if keypress[pygame.K_LEFT]:35 players[0].moveLeft(myboard)36 p1Direction[0] -= 137 if keypress[pygame.K_RIGHT]:38 players[0].moveRight(myboard)39 p1Direction[0] += 140 # player 1 keys for dropping bomb 41 if keypress[pygame.K_KP0]:42 players[0].dropBomb(myboard, bombs)43 # player 1 keys for using an Item 44 if keypress[pygame.K_KP1]:45 if players[0].item != 0 and players[0].itemDeploy == 0:46 players[0].useItem(myboard, p1Direction[0], p1Direction[1])47 # sets player 1 to standing still if no direction keys are pressed.48 if keypress[pygame.K_UP] != True and keypress[pygame.K_RIGHT] != True and keypress[pygame.K_LEFT] != True and keypress[pygame.K_DOWN] != True:49 players[0].standing = True50 51 #player 2 keys52 # for player 2 movement53 if keypress[pygame.K_w]:54 players[1].moveUp(myboard)55 p2Direction[1] -= 1 56 if keypress[pygame.K_s]:57 players[1].moveDown(myboard) 58 p1Direction[1] += 1 59 if keypress[pygame.K_a]:60 players[1].moveLeft(myboard)61 p2Direction[0] -= 1 62 if keypress[pygame.K_d]:63 players[1].moveRight(myboard)64 p2Direction[0] += 1 65 # key for p2 drop bomb66 if keypress[pygame.K_q]:67 players[1].dropBomb(myboard, bombs)68 # key for p2 to use items 69 if keypress[pygame.K_e]:70 if players[1].item != 0 and players[1].itemDeploy == 0:71 players[1].useItem(myboard, p2Direction[0], p2Direction[1])72 # sets player 2 to standing still if no direction keys are pressed.73 if keypress[pygame.K_w] != True and keypress[pygame.K_a] != True and keypress[pygame.K_s] != True and keypress[pygame.K_d] != True:74 players[1].standing = True75 76 if len(players) > 2: 77 # for player 3 movement78 if keypress[pygame.K_u]:79 players[2].moveUp(myboard)80 p3Direction[1] -= 1 81 if keypress[pygame.K_j]:82 players[2].moveDown(myboard) 83 p3Direction[1] += 1 84 if keypress[pygame.K_h]:85 players[2].moveLeft(myboard)86 p3Direction[0] -= 1 87 88 if keypress[pygame.K_k]:89 players[2].moveRight(myboard)90 p3Direction[0] += 1 91 92 if keypress[pygame.K_y]:93 players[2].dropBomb(myboard, bombs)94 95 if keypress[pygame.K_i]:96 if players[2].item != 0 and players[2].itemDeploy == 0:97 players[2].useItem(myboard, p3Direction[0], p3Direction[1])98 if keypress[pygame.K_u] != True and keypress[pygame.K_j] != True and keypress[pygame.K_h] != True and keypress[pygame.K_k] != True:99 players[2].standing = True100 101 if len(players) > 3: 102 # for player 4 movement103 if keypress[pygame.K_KP8]:104 players[3].moveUp(myboard)105 p4Direction[1] -= 1 106 if keypress[pygame.K_KP5]:107 players[3].moveDown(myboard) 108 p4Direction[1] += 1 109 if keypress[pygame.K_KP4]:110 players[3].moveLeft(myboard)111 p4Direction[0] -= 1 112 if keypress[pygame.K_KP6]:113 players[3].moveRight(myboard)114 p4Direction[0] += 1 115 116 if keypress[pygame.K_KP7]:117 players[3].dropBomb(myboard, bombs)118 119 if keypress[pygame.K_KP9]:120 if players[3].item != 0 and players[3].itemDeploy == 0:121 players[3].useItem(myboard, p4Direction[0], p4Direction[1])122 123 if keypress[pygame.K_KP8] != True and keypress[pygame.K_KP5] != True and keypress[pygame.K_KP4] != True and keypress[pygame.K_KP6] != True:124 players[3].standing = True125 126 if keypress[pygame.K_KP8] != True and keypress[pygame.K_KP5] != True and keypress[pygame.K_KP4] != True and keypress[pygame.K_KP6] != True:127 players[3].standing = True128 ...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1import pyautogui, time2from color import color_from_mouse3def keypress(key):4 pyautogui.keyDown(key)5 time.sleep(.5)6 pyautogui.keyUp(key)7def save():8 keypress('enter')9 keypress('up')10 keypress('up')11 keypress('up')12 keypress('x')13 keypress('x')14 keypress('x')15 keypress('x')#spams x to assure that the saving process screens have ended16 keypress('x')17 keypress('x')18 keypress('x')19 keypress('x')20 keypress('x')21 keypress('x')22 keypress('x')23 keypress('x')24 keypress('x')25 keypress('x')26 keypress('x')27 keypress('x')28 keypress('enter')#resets menu cursor29 keypress('down')#resets menu cursor30 keypress('down')#resets menu cursor31 keypress('down')#resets menu cursor32 keypress('enter')33 print('Game saved!')34 return35def perla(maxmin, wait, swi, ver, gen):36 pyautogui.FAILSAFE = True37 if wait:38 wait_time = wait * 6039 time.sleep(wait_time)40 if (swi == True):41 switchpos()42 save()43 red = 144 endtime = time.time() + 60 * maxmin45 pyautogui.PAUSE = .546 standard_color = game_color(ver,gen)47#Perla male standard color: (206, 170, 99)48 move_changes = 049 while time.time() < endtime:50 while color_from_mouse() == standard_color:51 keypress('right')52 keypress('left')53 print('Performed task %s times!' % red)54 red += 155 limit = time.time() + 18056 while not color_from_mouse() == standard_color:57 if time.time() < limit:58 keypress('x')59 keypress('x')60 print('Performed task %s times!' % red)61 red += 162 else:63 move_changes = exit_battle(move_changes)64 print('Performed task %s times!' % red)65 red += 166 limit = time.time() + 18067 move_changes = 5 68 while not color_from_mouse() == standard_color:69 keypress('x')70 if time.time() > limit:71 move_changes = exit_battle(move_changes)72 save()73 return74def switchpos():75 #pyautogui.PAUSE = 1.576 keypress('enter')77 keypress('down')78 keypress('x')79 time.sleep(2)80 keypress('x')81 time.sleep(1)82 keypress('down')83 time.sleep(2)84 keypress('x')85 keypress('right')86 keypress('right')87 keypress('x')88 time.sleep(2)89 keypress('z')90 time.sleep(2)91 keypress('up')92 keypress('enter')93 print('Positions switched!')94 return95def exit_battle(move_changes):96 keypress('z')97 keypress('z')98 keypress('z')99 keypress('z')100 keypress('down')101 keypress('right')102 keypress('x')103 keypress('x')104 keypress('x')105 keypress('x')106 keypress('x')107 return switch_move(move_changes)108def switch_move(move_changes):109 move_changes += 1110 diff = 3 - move_changes111 if move_changes > 3:112 pass113 else:114 keypress('enter')115 keypress('down')116 keypress('x')117 time.sleep(2)118 keypress('x')119 time.sleep(1)120 keypress('x')121 time.sleep(2.5)122 keypress('right')123 time.sleep(1)124 keypress('right')125 time.sleep(2)126 keypress('x')127 time.sleep(1)128 keypress('x')129 keypress('down')130 time.sleep(1)131 keypress('x')132 time.sleep(1)133 keypress('x')134 for x in range(0,diff):135 keypress('down')136 time.sleep(1)137 keypress('x')138 keypress('z')139 keypress('z')140 time.sleep(1)141 keypress('z')142 keypress('z')143 time.sleep(2)144 keypress('up')145 keypress('enter')146 return move_changes147def game_color(v,g):148 if v == 'Chaos' or v == 'Fire' or v == 'Leaf':149 if g == 'Female':150 return (239, 235, 255)151 else:152 return (255, 105, 74)153 elif v == 'Emerald':154 if g == 'Female':#Must place mouse cursor over hair not over hat!!155 return (165, 105, 82)156 else:#Must place cursor over hair not headband!!157 return (252, 248, 253)158 elif v == 'Sapphire' or v == 'Ruby':159 if g == 'Female':...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1import pyautogui2pyautogui.sleep(2)3def press(key, dur, times):4 for i in range(0, times):5 print(key)6 pyautogui.keyDown(key)7 pyautogui.sleep(dur)8 pyautogui.keyUp(key)9 pyautogui.sleep(longkeypress)10while True:11 keypress = 0.112 longkeypress = 0.2513 press('up', 0.01, 1)14 pyautogui.sleep(5)15 press(key='down', dur=keypress, times=7)16 pyautogui.sleep(2)17 press(key='right', dur=keypress, times=8)18 press(key='up', dur=keypress, times=2)19 pyautogui.sleep(2)20 press(key='left', dur=keypress, times=2)21 for x in range(0, 6):22 press(key='9', dur=keypress, times=1)23 pyautogui.sleep(12)24 press(key='z', dur=keypress, times=3)25 pyautogui.sleep(15)26 for i in range(0, 2):27 press(key='x', dur=keypress, times=1)28 press(key='z', dur=keypress, times=1)29 pyautogui.sleep(5)30 press(key='right', dur=keypress, times=1)31 press(key='down', dur=keypress, times=1)32 pyautogui.sleep(3)33 press(key='down', dur=keypress, times=1)34 press(key='left', dur=keypress, times=9)35 pyautogui.sleep(3)36 press(key='up', dur=keypress, times=1)37 pyautogui.sleep(3)38 press(key='up', dur=keypress, times=6)39 press(key='z', dur=keypress, times=4)40 pyautogui.sleep(5)41 for i in range(0, 2):42 press(key='z', dur=keypress, times=1)43 pyautogui.sleep(3)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful