Click here to Skip to main content
15,436,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python

i can send keyboards inputs to notepad using this code

import win32gui, win32ui, win32con

def main():
    window_name = "scriptkopya.txt - Not Defteri"
    hwnd = win32gui.FindWindow(None, window_name)
    hwnd = get_inner_windows(hwnd)['Edit']
    win = win32ui.CreateWindowFromHandle(hwnd)

    win.SendMessage(win32con.WM_CHAR, ord('A'), 0)

def list_window_names():
    def winEnumHandler(hwnd, ctx):
        if win32gui.IsWindowVisible(hwnd):
            print(hex(hwnd), '"' + win32gui.GetWindowText(hwnd) + '"')
    win32gui.EnumWindows(winEnumHandler, None)


def get_inner_windows(whndl):
    def callback(hwnd, hwnds):
        if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
            hwnds[win32gui.GetClassName(hwnd)] = hwnd
        return True
    hwnds = {}
    win32gui.EnumChildWindows(whndl, callback, hwnds)
    return hwnds

main()

but when i try to change window_name and hwnd = get_inner_windows(hwnd)['Edit'] (btw im trying to change to "Minecraft 1.8.9" and hwnd = get_inner_windows(hwnd)['LWJGL']) it doesnt work. Edit means Notepad Class Name if you didnt know, i putted minecraft Class Name instead of Notepad Class Name. I get classnames by using Microsof Spy++. I tried to get it by using

EnumChildWindows code but it didnt work out.

if you want detailed code here it is

import win32gui, win32ui, win32con

def main():
    window_name = "Minecraft 1.8.9"
    hwnd = win32gui.FindWindow(None, window_name)
    win = win32ui.CreateWindowFromHandle(hwnd)
    get_inner_windows(hwnd)


def list_window_names():
    def winEnumHandler(hwnd, ctx):
        if win32gui.IsWindowVisible(hwnd):
            print(hex(hwnd), '"' + win32gui.GetWindowText(hwnd) + '"')
    win32gui.EnumWindows(winEnumHandler, None)


def get_inner_windows(whndl):
    def callback(hwnd, hwnds):
        if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
            hwnds[win32gui.GetClassName(hwnd)] = hwnd
        return True
    hwnds = {}
    win32gui.EnumChildWindows(whndl, callback, hwnds)
    print(hwnds)

main()


when i run this code my output is " {} "
so instead of using this i used Microsoft Spy++ and i found this classname " LWJGL " but as you can see it didnt workout too.

import win32gui, win32ui, win32con

def main():
    window_name = "Minecraft 1.8.9"
    hwnd = win32gui.FindWindow(None, window_name)
    hwnd = get_inner_windows(hwnd)['LWJGL']
    win = win32ui.CreateWindowFromHandle(hwnd)

    win.SendMessage(win32con.WM_CHAR, ord('A'), 0)



def list_window_names():
    def winEnumHandler(hwnd, ctx):
        if win32gui.IsWindowVisible(hwnd):
            print(hex(hwnd), '"' + win32gui.GetWindowText(hwnd) + '"')
    win32gui.EnumWindows(winEnumHandler, None)


def get_inner_windows(whndl):
    def callback(hwnd, hwnds):
        if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
            hwnds[win32gui.GetClassName(hwnd)] = hwnd
        return True
    hwnds = {}
    win32gui.EnumChildWindows(whndl, callback, hwnds)
    return hwnds



main()


thats my final code i tried to change "Minecraft 1.8.9" to "javaw.exe" i dont get any error but i dont get any responds too.

btw im doing this tutorial https://www.youtube.com/watch?v=J3fatZ2OVIU&t=301s


What I have tried:

I tried to change "Minecraft 1.8.9" to "javaw.exe" but it didnt work out.
Posted
Updated 24-Dec-21 22:48pm

1 solution

If you are following a YouTube tutorial, then the best thing to do is contact the author via the comments below it. If they don't respond, the chances are they don't know either, and that's probably because they have about as much idea what is going on as you do - that's par for the course for YouTube tutorials which are made for likes and subscribes instead of to actual help you.
Finding a random website and asking for help on someone else's code isn't the best way to do things ...

If they don't respond, move on and find a better source of information.
 
Share this answer
 
Comments
Furkan Ünlü 25-Dec-21 5:26am    
Thanks im going to do right now

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