Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflowerror with Python 3.7 on Windows #186

Open
Aran-Fey opened this issue Jul 3, 2018 · 15 comments
Open

Overflowerror with Python 3.7 on Windows #186

Aran-Fey opened this issue Jul 3, 2018 · 15 comments

Comments

@Aran-Fey
Copy link

Aran-Fey commented Jul 3, 2018

The add_hotkey function doesn't work on Windows with Python 3.7 (64-bit):

import keyboard, time

keyboard.add_hotkey('a', print)

time.sleep(5)

The traceback:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Python37\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python37\lib\site-packages\keyboard\__init__.py", line 292, in listen
    _os_keyboard.listen(self.direct_callback)
  File "C:\Python37\lib\site-packages\keyboard\_winkeyboard.py", line 560, in listen
    prepare_intercept(callback)
  File "C:\Python37\lib\site-packages\keyboard\_winkeyboard.py", line 553, in prepare_intercept
    keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_callback, GetModuleHandleW(NULL), NULL)
ctypes.ArgumentError: argument 3: <class 'OverflowError'>: int too long to convert
@Farm-Art
Copy link

Farm-Art commented Jul 5, 2018

Not just the hotkeys, any attempt to create a hook fails.

@Giahieu
Copy link

Giahieu commented Jul 25, 2018

same here

boppreh added a commit that referenced this issue Jul 25, 2018
@boppreh
Copy link
Owner

boppreh commented Jul 25, 2018

I've improved the Win32 calls and it has fixed the problem in my system. Can you check the master branch on your side?

@zitrone47
Copy link

I had the same issue with python 3.5.2 when using pyinstaller, but the commit fixed it.

@Aran-Fey
Copy link
Author

Aran-Fey commented Aug 3, 2018

Sorry for the late response. The latest version on the master branch does indeed work as expected now. Thanks for the fix!

@majj
Copy link

majj commented Sep 13, 2018

the issue is still there for master branch with python 3.7 on Windows 64 bits. but it work with python 3.6.5.

@lkingscott
Copy link

lkingscott commented Oct 2, 2018

Issue still present using keyboard.is_pressed with python 3.7 and Python 3.7.1rc1 (v3.7.1rc1:2064bcf6ce, Sep 26 2018, 15:15:36) [MSC v.1914 64 bit (AMD64)] on win32

@GeorgeSp1
Copy link

Same with @lkingscott, I just tried this:

def stop():
	while True:#making a loop
	    if k.is_pressed('q'):#if key 'q' is pressed 
	        print('You Pressed A Key!')
	        global stop 
	        stop = True
	        break#finishing the loop
	    else:
	        pass

and i got

Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\threading.py", line 865, in run
self._target(*self._args, **self.kwargs)
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard_init
.py", line 292, in listen
_os_keyboard.listen(self.direct_callback)
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard_winkeyboard.py", line 560, in listen
prepare_intercept(callback)
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard_winkeyboard.py", line 553, in prepare_intercept
keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_callback, GetModuleHandleW(NULL), NULL)
ctypes.ArgumentError: argument 3: <class 'OverflowError'>: int too long to convert

on windows10 64bit with python 3.7

@lkingscott
Copy link

Same with @lkingscott, I just tried this:

def stop():
	while True:#making a loop
	    if k.is_pressed('q'):#if key 'q' is pressed 
	        print('You Pressed A Key!')
	        global stop 
	        stop = True
	        break#finishing the loop
	    else:
	        pass

and i got

Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\threading.py", line 865, in run
self._target(*self.args, **self.kwargs)
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard__init
.py", line 292, in listen
_os_keyboard.listen(self.direct_callback)
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard_winkeyboard.py", line 560, in listen
prepare_intercept(callback)
File "C:\Users\George\AppData\Local\Programs\Python\Python37\lib\site-packages\keyboard_winkeyboard.py", line 553, in prepare_intercept
keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_callback, GetModuleHandleW(NULL), NULL)
ctypes.ArgumentError: argument 3: <class 'OverflowError'>: int too long to convert

on windows10 64bit with python 3.7

Downgraded to Python 3.6.5 64 bit and problem goes away.

@Igli2
Copy link

Igli2 commented Jan 31, 2019

My problem is a bit more complicated...
I wrote a program, where you can select a hotkey, using the method keyboard.read_key()
Then I compiled the program with cx_Freeze. Everything worked fine, but when I started the program an error occured:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Users\Sebastian\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\Sebastian\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Sebastian\AppData\Local\Programs\Python\Python36\lib\site-packages\keyboard\__init__.py", line 292, in listen
    _os_keyboard.listen(self.direct_callback)
  File "C:\Users\Sebastian\AppData\Local\Programs\Python\Python36\lib\site-packages\keyboard\_winkeyboard.py", line 560, in listen
    prepare_intercept(callback)
  File "C:\Users\Sebastian\AppData\Local\Programs\Python\Python36\lib\site-packages\keyboard\_winkeyboard.py", line 553, in prepare_intercept
    keyboard_hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_callback, GetModuleHandleW(NULL), NULL)
ctypes.ArgumentError: argument 3: <class 'OverflowError'>: int too long to convert

The exception was thrown when the line "pressed_key = keyboard.read_key()" was executed. I put a print statement ahead of the line and after this line. Only the first one was printed.

@Alan-Solitar
Copy link

I am also having this issue with python3.7 on windows 10.

@muhammeteminturgut
Copy link

I am also having this issue with python3.7 on windows 10.

Same here.

@j-lag
Copy link

j-lag commented Feb 5, 2019

I m also having this issue with python3.7 and windows 10.
Quick and dirty fix: removing the call to GetModuleHandleW seems to work for my simple use case.

_winkeyboard.py line 553:
SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_callback, GetModuleHandleW(NULL), NULL) -> SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_callback, NULL, NULL)

@Igli2
Copy link

Igli2 commented Feb 5, 2019

Thank You :) This helped me a lot!

@ChristianJohnsten
Copy link

This also fixed the issue for me with Python3.7 and Windows 10 64Bit! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests