Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Help me understand the following code (Python)

Hi there,

I want to use the pyHook module in Python, and so I did follow a tutorial found on the wiki page of pyHook https://sourceforge.net/p/pyhook/wiki/PyHook_Tutorial/

And there I found the code for 'Keyboard Hooks', which works.

But I do not understand the 'event' variable? If I understand right, the 'event' variable is just an empty variable? Why is it treated like if it was a class or an instance? It does not have any properties whatsoever? I even tried to rename it to something else and it is still working, but how? This variable is not linked in any way to the pyHook module right?


Can someone please explain what is going on, it just doesn't seem to be logic to me?

Thanks in advance 🤝
If you see this line "hm.KeyDown = OnKeyboardEvent", the HookManager's instance is defined in such a way that you can have a callback function for every specific event. So in the example code, as per my understanding, the "OnKeyboardEvent" is a callback function when 'KeyDown' event happens. There might be a default callback and you are now overriding that function.

If you really wanted to understand it in whole deep level, I can try going through that class and help you with that :)
(Nov 18, 2017 05:35 AM)navdevl Wrote:  If you see this line "hm.KeyDown = OnKeyboardEvent", the HookManager's instance is defined in such a way that you can have a callback function for every specific event. So in the example code, as per my understanding, the "OnKeyboardEvent" is a callback function when 'KeyDown' event happens. There might be a default callback and you are now overriding that function.

If you really wanted to understand it in whole deep level, I can try going through that class and help you with that :)

I think I'm starting to understand better now, let me explain. So whenever OnKeyboardEvent(function) has been assigned as an instance of the KeyDown(class), now whatever name is put within the OnKeyboardEvent it just inherits the properties of an already existing variable within KeyDown(class) which is already an instance of another pyHook function and so all the properties are available within the variable that we provided, right?

Sorry if I over-complicated things, let me know if so 🤝


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by AzythumAug 2, 2024 10:19 AM 3 189 Aug 2, 2024 10:19 AM
Last Post: Perlo
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by mikehackMay 9, 2022 11:12 AM 2 151 May 9, 2022 11:12 AM
Last Post: mikehack