2

I have a laser pointer that I'm using along with my webcam as a drawing tablet, but I'd like to use the extra buttons on it too. They seem to be bound to Page Up, Page Down, Escape, and Period. I can't seem to figure out a way to get the input(which is handled like it's a keyboard) without any windows being selected.

I've tried serial and pyusb, but I've had issues with both of those. I got it to work with Pygame, but as far as I know, you can't receive input without the window it creates being selected. Any ideas?

CMLSC
  • 113
  • 1
  • 3
  • 13
  • Haven't tested this, but if you do not mind having a window, you could try using SDL2 and a newer function like [this](https://wiki.libsdl.org/SDL_SetWindowInputFocus) that forces your window to get focus. However, that function is only supported in X11. You could also try raising the window as a way to force window focus. – CodeSurgeon Nov 20 '17 at 18:46
  • @codesurgeon I'm using the setup I have to draw with GIMP, so I can't have another window focusing itself. – CMLSC Nov 20 '17 at 19:24
  • What platform are you running GIMP on? If it happens to use X11, you could use something low-level like `python-xlib` to make a keylogger to capture and send key events. – CodeSurgeon Nov 20 '17 at 19:30
  • @CodeSurgeon Windows 10. – CMLSC Nov 20 '17 at 19:38
  • Looks like there are a lot of youtube tutorials on the subject, surprisingly. [This](https://www.youtube.com/watch?v=x8GbWt56TlY) one shows a cross-platform approach using the `pynput` module, while [this](https://www.youtube.com/watch?v=8BiOPBsXh0g) one looks to be using a windows-specific approach (`pyhook` and `pythoncom`). Can't vouch for either of these as I just found them through some searching, and I am sure there are others as well. – CodeSurgeon Nov 20 '17 at 19:44
  • 1
    @CodeSurgeon pynput works perfectly! :D – CMLSC Nov 20 '17 at 20:03

2 Answers2

0

You could try making a python key-logger. However, it would be much easier to just use Pygame.

Tiskolin
  • 167
  • 17
  • I'm trying to make a key-logger, so I got pyHook from [here](https://sourceforge.net/projects/pyhook/). When I try to import pyHook, I get `ImportError: DLL load failed: %1 is not a valid Win32 application.` – CMLSC Nov 20 '17 at 19:33
  • Sounds like you are using Windows. In my experience, getting external packages for Python can be a real pain if you are using Windows, which is why Linux might make things easier. Found this: https://stackoverflow.com/questions/14629818/importerror-dll-load-failed-1-is-not-a-valid-win32-application – Tiskolin Nov 20 '17 at 22:09
0

CodeSurgeon answered me in a comment.

Looks like there are a lot of youtube tutorials on the subject, surprisingly. This one shows a cross-platform approach using the pynput module, while this one looks to be using a windows-specific approach (pyhook and pythoncom). Can't vouch for either of these as I just found them through some searching, and I am sure there are others as well.

I found that pynput works for me. (Windows 10/Python 3.4)

CMLSC
  • 113
  • 1
  • 3
  • 13