![]() |
|
[Python] Help me understand the following code (Python) - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Help me understand the following code (Python) (/showthread.php?tid=5754482) |
Help me understand the following code (Python) - CrypticX - Nov 18, 2017 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 🤝 RE: Help me understand the following code (Python) - navdevl - Nov 18, 2017 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 :) RE: Help me understand the following code (Python) - CrypticX - Nov 18, 2017 (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. 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 🤝 |