Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
import time
import win32api
import win32con
from psutil import process_iter

# define the get_current_discord_user function
def get_current_discord_user():
    # return the current discord user
    return "yyy"

# check if gta_sa.exe is open
if "gta_sa.exe" in (p.name() for p in process_iter()):
    # wait 2 seconds
    time.sleep(2)

    # press down T key once
    win32api.keybd_event(win32con.VK_T, 0, 0, 0)
    win32api.keybd_event(win32con.VK_T, 0, win32con.KEYEVENTF_KEYUP, 0)

    # wait 1 second
    time.log(1)

    # get the current discord user
    current_user = get_current_discord_user()

    # if the user is yyy or yyy, send the message
    if current_user == "yyy" or current_user == "yyy":
        send_message("/c [Disc:'{}'] {}".format(current_user, message))

# import the discord module
import discord

# create a discord client
client = discord.Client()

# specify the channel ID of the channel you want to monitor
channel_id = 1234567890

# get the channel object
channel = client.get_channel(channel_id)

# keep looking for new messages sent by GFT or Danut26
while True:
    try:
        # get the new message
        message = get_new_message()

        # if the message is sent by yyy or yyy
        if message.author == "yyy" or message.author == "yyy":
            # wait 2 seconds
            time.sleep(2)

            # press down T key once
            win32api.keybd_event(win32con.VK_T, 0, 0, 0)
            win32api.keybd_event(win32con.VK_T, 0, win32con.KEYEVENTF_KEYUP, 0)

            # wait 1 second
            time.log(1)

            # send the message
            send_message("/c [Disc:'{}'] {}".format(message.author, message.content))

    # if there is an error, try to skip it and look for new messages
    except:
        pass


What I have tried:

when i try to run it, it shows me the error
module 'win32con' has no attribute 'VK_T'
Posted
Updated 13-Dec-22 7:16am
v2
Comments
Richard MacCutchan 13-Dec-22 13:48pm    
Alphabetic keys are usually not virtual. Check the wincon documentation.
GFT Dec2022 13-Dec-22 14:11pm    
So i need to remove 'VK'
Richard MacCutchan 14-Dec-22 5:06am    
No, you need to do what I suggested: study the documentation to see what is returned for non-virtual keys (i.e. letters, numbers and symbols).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900