1

Is there a way to select a specific process via pid and have a script only input that process? New to python and I can't find this anywhere.

import keyboard
import time
import psutil

process_name = "NAME"
pid = None

for proc in psutil.process_iter():
    if process_name in proc.name():
       pid = proc.pid
print (process_name, proc.pid);
bot = 1
while bot:
    keyboard.press_and_release('ctrl')
    time.sleep(0.25)
bot += 1

My goal is to have this run while I browse online or do other work but I need the script to only run for a game I have installed. Instead of print am I able to have it concentrate on the game only? Hope this makes sense.

Strewn5490
  • 11
  • 2
  • So, you have the PID, but what do you mean "select the process"? Select the process how? Get a pointer to an object with methods that you can call on it, and properties you can get and set? What do you mean "have a script only input that process"? Are you wanting to write output from the script to the input of that process? I think you just need to explain what you're doing in a lot more detail, as you can tell from all the questions I have so far, you didn't include enough information in your post. – Random Davis Sep 20 '22 at 20:18
  • Does that make more sense? – Strewn5490 Sep 20 '22 at 20:28
  • Yeah. Maybe [this post](https://stackoverflow.com/a/71794911/6273251) has what you need? – Random Davis Sep 20 '22 at 20:36
  • Yes this seems like it will work once I get it working right. Thank you for the help!! – Strewn5490 Sep 20 '22 at 21:00

0 Answers0