Tap to unmute

Direct Input - Python plays Grand Theft Auto 5 p.3

  Рет қаралды 158,058

sentdex

sentdex

Күн бұрын

Пікірлер: 197
@mycollegeshirt
@mycollegeshirt 7 жыл бұрын
I like watching your videos cuz it feels like what it really feels like to code, instead of some pre-made stuff
@sentdex
@sentdex 7 жыл бұрын
Thanks!
@allmightqs1679
@allmightqs1679 6 жыл бұрын
@@sentdex, when I ran your code, I opened a notepad to see if it works or not and it did, so the code's working alright, but when I open gta5, it doesn't work. Do I need to make any changes in the settings?
@el-jay_
@el-jay_ 6 ай бұрын
7 years later as a Python newbie, I share this sentiment.
@RandomShowerThoughts
@RandomShowerThoughts 6 жыл бұрын
literally some of the best videos love the thought processes everything about these videos this is how coding really is rather than memorizing things. This is real problem solving
@youneskhouli
@youneskhouli 7 жыл бұрын
Hey man! I just wanna say that in the next two weeks, I will finish the third year in College studying "Software engineering", and I never had fun programming, the way I do right now after watching your video!!! Good job and thank you :)
@24HourMusic
@24HourMusic 7 жыл бұрын
VK is a Virtual Key and most games are set to ignore them to stop bots (I believe)
@sentdex
@sentdex 7 жыл бұрын
Thanks for the info!
@jakesmith8964
@jakesmith8964 7 жыл бұрын
hey im having trouble at this part, ive imported directkeys into my main file yet when I run it the vehicle still doesnt move what so ever
@ashleygodden1269
@ashleygodden1269 7 жыл бұрын
have you imported the directkeys file into your main file?
@pottingmix3733
@pottingmix3733 7 жыл бұрын
You can use windows api to send keys to a window handle either with postmessage or sendmessage. def Type(handle, string): for char in range(len(string)): win32api.SendMessage(handle, win32con.WM_CHAR, ord(string[char]), 0) time.sleep(.1) I have used this to make chat bots for certain games. For holding down a key you could use the WM_KEYDOWN flag from windows api.
@savijiN
@savijiN 5 жыл бұрын
@@sentdex I know I am replying to a 2 year old comment but I found if I run my python scripts through CMD as Administrator I often have my inputs go through fine with PyAutoGUI
@JulioPerez-ng9pt
@JulioPerez-ng9pt 7 жыл бұрын
1:50 Want pyautogui to do something but it doesn't. I had that problem. Yesterday I was trying to make pyautogui move mouse and click onto a button, it did moved but didn't clicked. Weird thing, Before I run the code, I click on app to be clicked (to focus), solution was to be the IDLE the one to be focused. I am a newbie and don't understand why is that, but that was the solution.
@relaxwithai
@relaxwithai 6 жыл бұрын
being a coder also i feel really bad copy pasting other people's code, expecially if I don't fully understand what's going on.. any advice on how i can get over this
@RandomShowerThoughts
@RandomShowerThoughts 6 жыл бұрын
try to figure out what each piece does
@georgebockari289
@georgebockari289 6 жыл бұрын
mildly sarcastic response...utterly genuine however. Just get over it. The task of being a developer is to rich a field to have working knowledge of every problem you will ever run across. Stackoverflow will and should already be a good friend of yours. Once you have a good grasp of the fundamentals of programming you'll be able to grab someone else's code to a problem you can't solve, skim it and get a feel if it seems to solve your issue. Plus the best part of coding is you just run it, if it does what you wanted, then its just a matter of figuring out how.
@vincelouse4409
@vincelouse4409 4 жыл бұрын
1. Instead of copying and pasting, find code that you'd copy and manually write it out. 2. after the first step look at parts of the code and search online to see what the code you just copied is doing and why it's implemented the way it is.
@westernvibes1267
@westernvibes1267 4 жыл бұрын
Copy pasting code is bad is a kind of myth. It's usually a coder's ego, don't let that ego consume you, knowing how to google is one of the important thing while coding or working on projects, a human simply can't have anwers to any question neither we can remember syntax of all the libraries and modules it's ok to google, take code, remake it, extend it. If you feel such things are supposed to make you feel bad watch big peoples coding stuffs from scratch, like geohot
@shmuelk3018
@shmuelk3018 7 ай бұрын
Thanks, it works, I am using this script to stay AFK without getting kicked from the session
@kevinvidzzz5393
@kevinvidzzz5393 7 жыл бұрын
Would be interesting to see how I could use some of this to program a "PokerBot". Not for evil purposes of course . . . Just to learn how to grab the screen . . . tweak the screen . . . apply some AI . . . Then do some mouse clicks based on the AI . . . Obviously I'm not the first person to have this in the back of their minds. Or a ChessBot . . . or any number of cool "Bots".
@sentdex
@sentdex 7 жыл бұрын
My plan is to certainly try to continue the "Python Plays" aspect of this series, and get Python to play a bunch of things. Not sure on poker, but possibly :P
@shahmi98
@shahmi98 7 жыл бұрын
Kevin Vidzzz im hoping for football game such as fifa or pes
@kevinvidzzz5393
@kevinvidzzz5393 7 жыл бұрын
Cool . . . not quite there yet . . . I just did a craps dice simulation in my latest video . . . I'm just about to upload it . . . I will be getting back to the poker bot stuff soon . . . ;)
@paranoidpenguin9077
@paranoidpenguin9077 7 жыл бұрын
Give World of Warcraft a shot, it would be interesting to see if you could use something like OpenCV to navigate towards resource nodes or to farm an area for for mobs. Although, considering that Blizzard tries to punish cheaters, I'd be interested to know if they have mechanisms in place to prevent this sort of behaviour.
@England91
@England91 7 жыл бұрын
Paranoid Penguin if you use it as a macro on your keyboard and or mouse then it might be hard for them to detect but that's just me thinking on the spot
@crustog11
@crustog11 6 жыл бұрын
what is the alternate library for MacOS for key interruption , it seems like "SendInput = ctypes.windll.user32.SendInput" needs to be replaced by alternative library for MacOS
@quadro201
@quadro201 7 жыл бұрын
9:25 ... lm gonna be a good boy and not block the way of other cars :D
@JadenAccord
@JadenAccord 7 жыл бұрын
Could you put the links for the stackoverflow and other sites in the description? It would be a lot easier to follow you like that.
@sentdex
@sentdex 7 жыл бұрын
all the code is sourced on the project github and pythonprogramming.net. This specfic tutorial on ppnet for example: pythonprogramming.net/direct-input-game-python-plays-gta-v/ The links to the code sourced elsewhere are commented in the code.
@kshitijohri5285
@kshitijohri5285 3 жыл бұрын
I'm having an error saying :-cannot import name 'Presskey' from 'directkeys' both files are in the same directory
@KellenChase
@KellenChase 7 жыл бұрын
nice. I used PyAutoGui to program myself out of my last job for a while. had to learn the scan codes to get around some things that wouldn't take the standard pyautogui inputs.
@vijayabhaskar-j
@vijayabhaskar-j 7 жыл бұрын
Awesome Idea!,The best ML idea with fun,I have seen in youtube!
@sentdex
@sentdex 7 жыл бұрын
Thank you, this is easily the most fun I've had with a series so far as well.
@danielguarchaj4836
@danielguarchaj4836 6 жыл бұрын
I just loved this, great work!
@gstexpla63
@gstexpla63 7 жыл бұрын
Hi! So the funda is that the window you want to send the keys to ('w' in this case) should be in 'focus' at the time the keys are being 'sent' to it. Windows will just send the keys to whatever window happens to be in focus at the time of code execution. Since the window in your code that is in focus is the IDLE window, the keys are not being sent to the GTA window. A shabby workaround I found in my intern was this: 1. Using pyAutoGUI use the mouse to 'click' the window you want to send the keys to 2. now send the actual keys I suppose you can figure out the mouse click part. This worked for me, I suppose the 'Alt+Tab' combo could also be sent through the code for such a task.
@shubhamdebnath714
@shubhamdebnath714 7 жыл бұрын
i've just confirmed, using just pyautogui.DownKey, works only for older games or the ones not using newer DX like COD 4 and crossout. the games that didn't work were witcher 3, COD WW2, in both cases i used the same code and alt-tab
@beckettman42
@beckettman42 7 жыл бұрын
Fun choice of topic. I will have to come back to this when GTA V goes on sale.
@sentdex
@sentdex 7 жыл бұрын
You can also use another GTA (maybe, IIRC GTA 3 doesn't work well on windows 7+), but you could also just use San Andreas. Super cheap on Steam. Just for the record, I am not sponsored in any way, just think it's a great came for playing with AI in. If you have another game where you drive a car and can clearly see lanes, that can also work, we're going to be doing self-driving cars for a bit, til I can speed through the city :D. None of the methods used here will be GTA-specific, besides maybe some mods I use to make no traffic, lots of traffic, clear skies...etc :P
@beckettman42
@beckettman42 7 жыл бұрын
Excellent. This will be fun! At this rate Ornstein and Smough are doomed to fall to python.
@veerendra.k
@veerendra.k 7 жыл бұрын
Thanks for the great tutorials. I tried same code in my laptop(Acer, Nvidia) GTA 5, it is not working for me. But it is working in "Batman: Arkham Origins". Still I don't understand what I'm missing. Any help?
@Paavo1991
@Paavo1991 7 жыл бұрын
I didn't know that you can write [::-1] after for loop, nice but how it works?
@sentdex
@sentdex 7 жыл бұрын
To be honest, I have no idea why ::-1 works like that, I just know it does. Mainly the :: part means go backwards. -1 means go backwards from the -1st index (the last one). Why :: means reversed though .. I just don't know.
@Paavo1991
@Paavo1991 7 жыл бұрын
Yup, I know that [::-1] works "reversed" but I've never seen it next to the list() function. Thanks for tutorials :)
@chronicfantastic
@chronicfantastic 7 жыл бұрын
I think you've got this wrong? list slicing is [start: stop: increment], where if no value is given for start:stop it defaults to start:end so :: means go from the start to the end (unspecified), and the -1 means in reverse increments
@Zenzodiene
@Zenzodiene 7 жыл бұрын
And perhaps you can use it next to the list function since a "slice" returns a list. So it basically says for i in list.
@benburrill
@benburrill 7 жыл бұрын
The `list()` just converts the range object to a list because +sentdex is under the (incorrect) impression that Python 3 range objects cannot be sliced. Once it is a list, the [::-1] works just like the [::-1] on any other list: it creates a new, reversed list object. However, because Python 3's range objects are more powerful than many give them credit for, you can just slice the range, returning a new reversed range object: >>> range(4)[::-1] range(3, -1, -1) This would be better because it not only takes up less typing, but also is more efficient in time and memory use because Python 3's range objects do not store each value like a list does, they just calculate them on the fly when you ask for them. In this case it doesn't really matter because there are just 4 values in the range, but this would matter for bigger ranges.
@kanishqvijay2852
@kanishqvijay2852 4 жыл бұрын
You can use pydirectinput module, which has same functions like pyautogui. It can work where VK input won't work
@sourabhjangid8013
@sourabhjangid8013 4 жыл бұрын
pydirectinput works only for windows is there any similar for ubuntu
@kanishqvijay2852
@kanishqvijay2852 4 жыл бұрын
@@sourabhjangid8013 Try using pynput module
@kanishqvijay2852
@kanishqvijay2852 4 жыл бұрын
@@sourabhjangid8013 "Maybe" run python in wine in Ubuntu. And use the pydirectinput(im not sure about this method)
@abdelkaderguellati5164
@abdelkaderguellati5164 2 жыл бұрын
I had same problem of sending key presses or controlling mouse for a while. it turned out you need to run the script as administrator and worked .thnx for the videos though
@bharathbabuyp
@bharathbabuyp 7 жыл бұрын
It's a pleasure to watch your videos. Awesome Harrison!!! Not sure if it has been implemented later on, but you could try to run the keyboard events in a parallel thread, right?. Correct me if its not possible. I haven't tried it though. But still, its an awesome topic man :)
@tonysmn97
@tonysmn97 7 жыл бұрын
For those, who are on Linux, you can use this library: github.com/SavinaRoja/PyUserInput (Though it says it works on Windows, Mac, Linux) I've tested it, works prefect and supports all kinds of keys and even a mouse events
@YumekuiNeru
@YumekuiNeru 7 жыл бұрын
xlib is just endless pain and suffering to work with (but it tends to work)
@YoloMonstaaa
@YoloMonstaaa 6 жыл бұрын
How are y'all playing GTA on Linux?
@mogarbobac1472
@mogarbobac1472 6 жыл бұрын
from KeyPresses import ReleaseKey, PressKey, W, A, S, D ImportError: cannot import name 'ReleaseKey' !!Please Help!! im using Jupiter notebook. all i did was name it KeyPresses instead. what could be causing this issue
@machwave540
@machwave540 6 жыл бұрын
Hey @Sentdex can you do videos on Carla? its an opensource autonomous driving simulator.
@BoomTownNL
@BoomTownNL 7 жыл бұрын
I can't seem to get mouse clicks working. When I try to assign mouse1 to 0x100 (scancode 256) it does nothing, and 0x101 for mouse2 seems to press esc for some reason. Is there something i'm missing?
@sentdex
@sentdex 7 жыл бұрын
I wish you or I knew! I want to get a way to drive smoother bad!
@IyaJenkei
@IyaJenkei 6 жыл бұрын
Man I've searched every thread relating to this stuff it feels like and I can't get mouse clicks to work right. when I try the hex codes that are supposed to work it ends up pressing keyboard keys? No chance you ever came up with anything is there? I'm trying to make a civilization 6 bot and the whole game is mouse clicking. I guess if I have to I can look up all the keyboard shortcuts and hopefully there's one for every action
@glorytoarstotzka330
@glorytoarstotzka330 6 жыл бұрын
i found a way : you need to download an autoclicker like autoclicker professional , and its key to use it its F1 , so put a huge delay on the clicks then instead in the program of making bot click , make it press F1 , then F2 after 0.5 secs , this should fix problem , if F1 is start key for autoclicker and F2 is the other , and i believe you can use pyautogui for F1 and F2
@m3n4lyf
@m3n4lyf 6 жыл бұрын
I like how he is talking about replacing time.sleep() in a loop that is using time.time() for instrumentation.
@someaccount3438
@someaccount3438 6 жыл бұрын
Finally... Last year, I was trying to make a bot for a game, and I gave up, having never figured out how to make keystrokes work. I had used many methods, but not this one. Surprisingly, I had also stumbled across the piece of code that you copied from Stackoverflow, but it seemed too confusing, so I just left it. I was so hyped when I finally managed to get the game to catch the key this year, when I was trying to make another bot. Thank you.
@sentdex
@sentdex 6 жыл бұрын
Awesome! What game are you doing?
@someaccount3438
@someaccount3438 6 жыл бұрын
sentdex I did Warframe. Nothing complicated, I just needed it to post a message every 120 seconds. Turns out, win32com.client's SendKeys can be used for writing in chat, but not for keys in game. All I needed was to press enter so the chat would open. I ended up using this solution here for that, and kept using SendKeys for writing. Turned out great!
@otacon1024
@otacon1024 4 жыл бұрын
@@someaccount3438 Funny you should mention Warframe, I also made one for scrolling through my inventory and running OCR to get a list of all the items I had and their counts. Combined with pulling prices from warframe.market it made it way easier to figure out exactly what I could sell and for how much platinum.
@Katatonya
@Katatonya 2 жыл бұрын
@@otacon1024 yo how did you get OCR to be consistent with the warframe font? I've always had trouble with that, OCR libraries I tried like tesseract don't work on all fonts no matter how many parameters I tweaked.
@iRetroGamingz
@iRetroGamingz 4 жыл бұрын
ur a legend even 3 years down the like tysm
@henoktilaye3152
@henoktilaye3152 4 жыл бұрын
Big time fan. Late to the party. pyautogui is working for me on ubuntu.
@tazbird
@tazbird 7 жыл бұрын
I ran into a similar issue with pyautogui when I was automating an app that was running through Citrix. it wouldn't take the VKs either, I ended up editing pyautogui adding a dictionary to lookup the scan code and then just tweaking the keyb_event call to take 'the looked up' scan code in the 2nd parameter (it's hard-coded to 0 in Sweigart's code)
@nihaalmodi6884
@nihaalmodi6884 7 жыл бұрын
Hello Sentdex, If you start four new thread two for left right and two for up down along with queue, you will be able to use pyautogui for controlling the character/car
@deknas1407
@deknas1407 5 жыл бұрын
11:47 how do u comment out code like that?
@gurkiratsingh348
@gurkiratsingh348 5 жыл бұрын
Alt+3
@ifredpingplay468
@ifredpingplay468 5 жыл бұрын
hi it was working in other games except for GTA V I tried in GTA V to while ago and it was working .Key is being pressed and Release everything is working except in GTA V, Direct Input required particular DirectX version?
@mihaiandrei-daniel4485
@mihaiandrei-daniel4485 5 жыл бұрын
: expected LP_INPUT instance instead of LP_Input Any ideas guys?
@siddheshgawali7764
@siddheshgawali7764 6 жыл бұрын
how can i code the same for pubg emulator... cus it cant take input from direct keys
@jaeminpark3113
@jaeminpark3113 7 жыл бұрын
Hi, I would appreciate it if anyone could explain what if __name__ == '__main__' does... around 5:35 ..
@wookiecharge1189
@wookiecharge1189 7 жыл бұрын
main means that it is teh whoel code on tehat page the under scores mean its "special"
@khoapham3083
@khoapham3083 4 жыл бұрын
Hello, i still can not let python press the key in GTA V even though used keyPress just like you, can you help me ? I am using python 3.7.7 (64bit) and DirectX 10.1 and 11 (both doesn't work)
@pizzafoot1966
@pizzafoot1966 6 жыл бұрын
Hey Sentdex (or anybody else, seriously), you wouldn't happen to know why my _keys_ are working in pyautogui, but my _mouse_ isn't? I am working on mac High Sierra, though, so it's quite a bit different. In Minecraft, the clicks and mouse movement actually work perfectly fine on menus, but in actual gameplay the mouse movements just jitters once you actually move the mouse. Is it just the way that the mouse is used in video games?
@MatterStorm1
@MatterStorm1 6 жыл бұрын
If you're telling it to move the mouse to a specific position on the screen or a certain amount in a certain direction, that's just a single sudden movement. Real human mouse movement is continuous. In menus and on your desktop it doesn't really matter since everything has an absolute position on the screen and you're just moving your cursor around, but in a first person game where you're controlling a camera, it will look jittery if you tell the mouse to move suddenly. Perhaps you could make it looks slightly smoother by spreading the total movement you want out over several steps of max distance ~20 pixels or something with a for loop and some simple vector math. If you need to you could do time.sleep(0.005) and try out values for that to give it a bit more slowness.
@boredgaming91
@boredgaming91 6 жыл бұрын
same code not working on my GTA V i have a wireless keyboard Observations: when i give input W in PressKey it kindof presses LCtrl on text document it prints nothing, the cursor just moves left
@jlewwis1995
@jlewwis1995 7 жыл бұрын
Why would you *NOT* send scancodes to the game input? I thought all virtual keypress programs used scancodes... apparently I was wrong? What is even the benefit of non scancode VKs?
@sentdex
@sentdex 7 жыл бұрын
I wondered the same thing when I learned that modules like pyautogui and sendkeys were just using some 2ndary form of input. I guess it's so a machine could differentiate between the presses if necessary, not sure why that would be necessary...but possible!
@esequielalbornoz5271
@esequielalbornoz5271 6 жыл бұрын
Hi... i know im a year late but. How can i send mouse movements with direct input? im trying but it alway move to the same position (center of th screen)
@mauipomare3232
@mauipomare3232 5 ай бұрын
Forget `time.time()`. It's for checking the current time, not for measuring how long something takes. Use `time.perf_counter()` instead. It's designed for precision and high-resolution timing, perfect for when you need to measure the exact duration between events.
@allmightqs1679
@allmightqs1679 6 жыл бұрын
Sentdex, when I ran your code, I opened a notepad to see if it works or not and it did, so the code's working alright, but when I open gta5, it doesn't work. Am I making a mistake, or do I need to make any changes in the settings?
@SandeepKumarz1671995
@SandeepKumarz1671995 7 жыл бұрын
help..!! I have done exactly the same but the key wont work. when I tried to see what it is doing then I found that it printed the key once after PressKey(W) and this single press dont work in Game. Thanks in advance.
@kingcheng2000
@kingcheng2000 6 жыл бұрын
Is that working now ?
@allmightqs1679
@allmightqs1679 6 жыл бұрын
It's not working for me either
@agianzariskyarbhama8097
@agianzariskyarbhama8097 3 жыл бұрын
@@allmightqs1679 i have some problem i can't use the direct input, this code don't work in my project @sentdex
@GregorEpet
@GregorEpet 7 жыл бұрын
Just noticed in this episode: How do you run PIL in Python 3.x? I can only find PIL for 2.x online
@srikanthvelpuri2973
@srikanthvelpuri2973 7 жыл бұрын
Hackfleisch Hackender Zerhacker Install pillow module and it contains PIL in python 3.0 ..Hope this helps you.
@jesusalejandrocorneliotruj5013
@jesusalejandrocorneliotruj5013 4 жыл бұрын
But how do I move the camera with mouse code in games with raw_input
@NoobishAlpha
@NoobishAlpha 4 жыл бұрын
Does pynput work for inputing data in a game ?
@I3LaCkPeArL
@I3LaCkPeArL 5 жыл бұрын
Didn't work for my game. They keystrokes still dont appear ingame, only in other applications. Are there other ways to simulate direct keystrokes?
@user-df4zw7yb4v
@user-df4zw7yb4v 5 жыл бұрын
run the code as a .pyw file Run it by clicking on the file itself, not within the code editor
@venishpatidar3991
@venishpatidar3991 5 жыл бұрын
Dexter Morgan or run code editor as administrator.
@JurassicJordan
@JurassicJordan 6 жыл бұрын
how do i accomplish this in mac os, without a user32 api?
@foxrain4791
@foxrain4791 3 жыл бұрын
Thank you! I love this video♥
@GauravSuryawanshi
@GauravSuryawanshi 6 жыл бұрын
Hey what are those 0x11 and this nomenclature?
@kolterdyx
@kolterdyx 5 жыл бұрын
where can i find the keys thing to copy and paste?
@AdamSaudagar
@AdamSaudagar 7 жыл бұрын
please put links of stuff u copy code from (even for testing) in the description
@tgautam03
@tgautam03 4 жыл бұрын
Is there any way to do this for a controller?
@jakehappenpal8165
@jakehappenpal8165 4 жыл бұрын
Doesn't work for me. Game doesn't accept that directkeys input
@allmightqs1679
@allmightqs1679 6 жыл бұрын
The code doesn't throw any errors, but my bike doesn't move either. Can anyone tell me what's going wrong?
@codewithlenny
@codewithlenny 7 жыл бұрын
Hey Sentdex i am doing this on GTA Vice City and the directKeys is not working.My PC can't play GTA V....It's too big .Any suggestions to other games like GTA that will work out for me??
@sentdex
@sentdex 7 жыл бұрын
Try pypautogui's "key" functions like keyUp and keyDown ...vice city might not be using direct inputs, that's an older game, so you might actually be fine with the virtual keys stuff. pyautogui.readthedocs.io/en/latest/
@allmightqs1679
@allmightqs1679 6 жыл бұрын
@@sentdex When I ran your code, I opened a notepad to see if it works or not and it did, so the code's working alright, but when I open gta5, it doesn't work. Do I need to make any changes in the game settings or am I doing something wrong?
@bhagyeshkocharekar8850
@bhagyeshkocharekar8850 6 жыл бұрын
not working for CS:GO and Rainbow six siege. Any help ?
@mehDfd
@mehDfd 6 жыл бұрын
run the script then select csgo windows to work
@fuba44
@fuba44 7 жыл бұрын
Great idea for a video series!
@sentdex
@sentdex 7 жыл бұрын
Thanks, it's been a lot of fun working on it!
@thepiratedeveloper8807
@thepiratedeveloper8807 6 жыл бұрын
How would you send mouse clicks?
@slashhack1026
@slashhack1026 7 жыл бұрын
I am so happy to meet you.
@pradyumanpareek2972
@pradyumanpareek2972 5 жыл бұрын
I tried running the code by same procedure and it is not showing any error and it's not running in GTA V. Please Help....
@venishpatidar3991
@venishpatidar3991 5 жыл бұрын
PRADYUMAN PAREEK Run ur IDE as administrator and try to run code again.
@Osama_Amer
@Osama_Amer 2 жыл бұрын
damn i went through with the same thought process for PyAutoGUI, gave me a headache.
@ifredpingplay468
@ifredpingplay468 5 жыл бұрын
GG! but how can I pass 2 keys at a single time like lSHIFT+W for sprint?
@Myrkvi_
@Myrkvi_ 5 жыл бұрын
You do PressKey for both. e.g. first PressKey(L_SHIFT) and then PressKey(W), and then release both later.
@khoapham3083
@khoapham3083 4 жыл бұрын
Okay, i know it a bit late but if you can not run your gta 5 like him, you MUST run GTA V and Python IDLE as administrator
@andrejkaradzic5684
@andrejkaradzic5684 7 жыл бұрын
Why do you use a text editor instead of some IDE?
@sentdex
@sentdex 7 жыл бұрын
IDLE is an IDE :P
@SpirosKaftanis
@SpirosKaftanis 7 жыл бұрын
Do you know how to send half key? or 30% key pressed?
@sentdex
@sentdex 7 жыл бұрын
You'd need to emulate a controller, which I am doing with vjoy + x360ce for GTA V now.
@Lee-ie1xg
@Lee-ie1xg 7 жыл бұрын
Help! I cannot seem to get the 'W' key to move my character in GTA. What i observed is when i run the code without clicking on GTA window, it will type 'w' in the shell. However, it does not type 'w' when i tab over to GTA, yet there is no response in the game. Is GTA blocking the signals sent? How can I get it to work. Please let me know. Thank you.
@Lee-ie1xg
@Lee-ie1xg 7 жыл бұрын
Also can anyone let me know what GTA Mod he is using to change the weather, time, location etc. Thank you!
@aniketbhanavase7790
@aniketbhanavase7790 7 жыл бұрын
I had the same issue...run GTA 5 as administrator and python script too:)
@srikanthvelpuri2973
@srikanthvelpuri2973 7 жыл бұрын
I too had the same issue? Found the fix..Please let me know
@srikanthvelpuri9300
@srikanthvelpuri9300 7 жыл бұрын
Thanks Aniket..It solved my issue
@talrofe5558
@talrofe5558 6 жыл бұрын
Thanks. This comment should be pinned
@npcode
@npcode 6 жыл бұрын
Why not Keyboard lib?
@niklaskras5498
@niklaskras5498 2 жыл бұрын
Awesome to see that even though you are a way better programer than i am you still dont write perfect code and use the "start the programm, get a error, fix the error" type of programming cycle.
@Tibetan-experience
@Tibetan-experience 6 жыл бұрын
it dose not work for mac OS
@johncusack3646
@johncusack3646 7 жыл бұрын
How can you track mouse movement with python?
@sentdex
@sentdex 7 жыл бұрын
That's a great question for the google. pyautogui can do it, but I don't know if it works in this environment.
@johncusack3646
@johncusack3646 7 жыл бұрын
What about an Xbox controller? I want to make a mayhem bot, he just aims and shoots an RPG at cars and cops
@ravernot8889
@ravernot8889 7 жыл бұрын
seriously though- do you teach an actual class?
@sentdex
@sentdex 7 жыл бұрын
Nope I don't. I've been able to reach over a million people through pythonprogramming.net and youtube. Something just not possible if I was physically teaching. I also don't like the idea of teaching the same thing over and over. ...finally, I don't have credentials. Universities want you to have a degree, usually phd/masters in what you teach. I have no such thing for anything even remotely close to CS.
@easter.bunny.6
@easter.bunny.6 7 жыл бұрын
8:20 pressing and releasing have different hardware event code so lmao xD
@ishanksharma9051
@ishanksharma9051 7 жыл бұрын
amazing dude please keep this up
@derekverveer6058
@derekverveer6058 7 жыл бұрын
Edward snowden, Is that you?
@JoaoMartins-qc4oh
@JoaoMartins-qc4oh 5 жыл бұрын
I cant use it in my game. Can someone help me?
@ronyyosef513
@ronyyosef513 4 жыл бұрын
did u get a answer?
@JoaoMartins-qc4oh
@JoaoMartins-qc4oh 4 жыл бұрын
@@ronyyosef513 Nop
@Zippka_
@Zippka_ 4 жыл бұрын
some shit a while ago that I tried in LoL, ended using AutoHotkey. Basically put the exe in python folder and install AHK library via pip and it worked really nice
@varshneydevansh
@varshneydevansh 5 жыл бұрын
*AI God Sentdex*
@phluent2181
@phluent2181 5 жыл бұрын
did u make another video
@sentdex
@sentdex 5 жыл бұрын
I made *many* more. Here's the full playlist: pythonprogramming.net/game-frames-open-cv-python-plays-gta-v/
@hadjseddikyousfi00
@hadjseddikyousfi00 5 жыл бұрын
Guys using linux distributions how did you use ctypes lib ? @sentdex fans PLZ HELP
@祐祐風風
@祐祐風風 7 жыл бұрын
part-2-and-3-keyboard-input-and-basic-OpenCV.py It need to add extra line: if __name__=="__main__": main() it can be work
@krazzysingh3980
@krazzysingh3980 6 жыл бұрын
the code was for teaching tho..so no license
@yadavdenrose
@yadavdenrose 5 жыл бұрын
NameError: name 'get_ipython' is not defined How to solve this error? Do i need jupyter notebook for these codes?
@marcosmarcolas8201
@marcosmarcolas8201 5 жыл бұрын
cv2.imshow('window, new_screen) ^ SyntaxError: EOL while scanning string literal
@ubwr5322
@ubwr5322 5 жыл бұрын
you need to close the string: cv2.imshow('window', new_screen) rather than: cv2.imshow('window, new_screen)
@rednax3788
@rednax3788 7 жыл бұрын
Why don't you have one thread doing the processing, and another thread doing the inputs and shit
@sentdex
@sentdex 7 жыл бұрын
Sure, that's possible, if you want to do a pull request and show how you think it should be done: github.com/sentdex/pygta5/
@walpurgoffnacht
@walpurgoffnacht 6 жыл бұрын
Hello sentdex! This might be a year later, but i think i found out why you think you didnt need ReleaseKey i am making a similar bot for a game with arrowkeys, and it turns out arrowkeys only register as one press, so you didnt need to use ReleaseKey
@shinsawai1
@shinsawai1 7 жыл бұрын
Does anyone know how to get this to work on a Mac?
@chilliam65
@chilliam65 7 жыл бұрын
I use pyautogui and it works fine
@JurassicJordan
@JurassicJordan 6 жыл бұрын
@@chilliam65 not for me, according to the terminal return, i need windll, a windows system file
@TechHackerTamilOfficial
@TechHackerTamilOfficial 4 жыл бұрын
this guys has 4 monitors in front
@Salata_kepu
@Salata_kepu 8 ай бұрын
Nice vid, helped!!!
@kanedsodas
@kanedsodas 5 жыл бұрын
did anyone notice that he has a typo in the folder name "ai-gamging"?
@jackpaul9393
@jackpaul9393 6 жыл бұрын
So much off copy paste work doesn't seems to be tutorial, live code is better than debugging copy paste code
@sentdex
@sentdex 6 жыл бұрын
So long as you never import a library in Python, you can make that claim. Otherwise...wot?
@parthikbhandari6903
@parthikbhandari6903 5 жыл бұрын
GTA V ain't taking input using this code too. Somebody save me. I'm done with all other frameworks, finding lanes and all (though I used a different method to find lanes, I didn't want to just copy everything from you), now I'm only stuck at giving inputs. I even copied and pasted your code from Github as it is, still, no good! Here's my stack link to the question: stackoverflow.com/questions/56846010/direct-input-command-not-working-while-making-gamebot
@u00xclub
@u00xclub 5 жыл бұрын
For most of the game nowadays you have to run it as an administrator, since the game doesn't allow things from outside to interfere with the game, that's also why most of the "cheats" are internal(in the game)
@tellvivk
@tellvivk 7 жыл бұрын
that brain freeze tho 😂
@arvindroshaan
@arvindroshaan 7 жыл бұрын
Pyautogui will work for controlling the movements. The code is given below, print('down') press_w_start_time = time.time() while time.time()-press_w_start_time
@sentdex
@sentdex 7 жыл бұрын
No, that doesn't work. You need direct input.
@arvindroshaan
@arvindroshaan 7 жыл бұрын
No Sir, it works. The logic is to press 'w' continuously for 3 seconds (in this example) using while loop and after that release 'w' using keyup. I have tried it in GTA SA, and it worked as expected. Kindly cross-check. Thank you.
@sentdex
@sentdex 7 жыл бұрын
Maybe it works in GTA SA, but doesn't work in GTA V. Again, you need direct input for current-aged games. I did try when I first began this project.
@shubhamdebnath714
@shubhamdebnath714 7 жыл бұрын
i've just confirmed, using just pyautogui.DownKey, typewrite(), works only for older games or the ones not using newer DX like COD 4 and crossout. the games that didn't work were witcher 3, COD WW2, in both cases i used the same code and alt-tab and yeah this comment i posted again
@akilkhan2955
@akilkhan2955 5 жыл бұрын
Does this require running the script as an admin? Coz at the moment, i'm able to alt+tab into the game but the game's not recognizing the keyboard events or mouse clicks. I'm trying on Gta SA btw.
@hydroblitz3307
@hydroblitz3307 6 жыл бұрын
stackoverflow.com/questions/14489013/simulate-python-keypresses-for-controlling-a-game is the site
@hope-kz6tb
@hope-kz6tb 2 жыл бұрын
Please teach us how to create a bot for fucking clash of kings game
@hope-kz6tb
@hope-kz6tb 2 жыл бұрын
I know you will not read my comment but if accidentally you read it so please create video on it and teach me how can provide bots for games and provide services to earn some money
@bennis9283
@bennis9283 7 жыл бұрын
Great!
@JS-ys2uk
@JS-ys2uk 7 жыл бұрын
"You can probably guess what's about to happen" No I can't because I'm still a noob, but this is fun to watch! :)
ROI - Python plays Grand Theft Auto 5 p.4
13:32
sentdex
Рет қаралды 112 М.
Automating Android Games with Python: Stick Hero
15:22
Engineer Man
Рет қаралды 386 М.
$1 vs $500,000 Plane Ticket!
12:20
MrBeast
Рет қаралды 122 МЛН
Self-driving Car - Python plays Grand Theft Auto 5 p.7
15:10
sentdex
Рет қаралды 249 М.
Shenzhen I/O - Building Cheap Chinese Electronic Gizmos
17:31
Scott Manley
Рет қаралды 365 М.
Meet the 26-Year-Old Hacker Who Built a Self-Driving Car... in His Garage
6:52
Bloomberg Originals
Рет қаралды 1,7 МЛН
AI learns to play Google Chrome Dinosaur Game || Can you beat it??
10:21
I Scraped the Entire Steam Catalog, Here’s the Data
11:29
Newbie Indie Game Dev
Рет қаралды 811 М.
Why Majora's Mask's Blue Dog Took 25 Years to Win the Race
21:04
Vidya James
Рет қаралды 2,6 МЛН
Make Python code 1000x Faster with Numba
20:33
Jack of Some
Рет қаралды 448 М.
I tried to make a Valorant AI using computer vision
19:23
River's Educational Channel
Рет қаралды 1,5 МЛН