用Windows10桌面图标玩python贪吃蛇

文中键盘监听部分借鉴了cnblog的‘十一月_寒风’大佬的文章python监听键盘和鼠标事件

from  win32gui import*
from time import sleep
from random import randint
from threading import Thread
from math import*
from commctrl import*

from ctypes import *
from ctypes import wintypes
import win32con
SetWindowsHookEx=windll.user32.SetWindowsHookExA
UnhookWindowsHookEx=windll.user32.UnhookWindowsHookEx
CallNextHookEx=windll.user32.CallNextHookEx
GetMessage=windll.user32.GetMessageA
GetModuleHandle=windll.kernel32.GetModuleHandleW
#保存键盘钩子函数句柄
keyboard_hd = None
#保存按键
key = None
class KBDLLHOOKSTRUCT(Structure):
    _fields_ = [
        ('vkCode',c_int),
        ('scanCode', c_int),
        ('flags', c_int),
        ('time', c_int),
        ('dwExtraInfo', c_uint),
        ('',c_void_p)
    ]
def wait_for_msg():
    msg = wintypes.MSG()
    GetMessage(msg, 0, 0, 0)

def keyboard_pro(nCode, wParam, lParam):
    """
    函数功能:键盘钩子函数,当有按键按下时此函数被回调
    """
    global key
    if nCode == win32con.HC_ACTION:
        KBDLLHOOKSTRUCT_p = POINTER(KBDLLHOOKSTRUCT)
        param=cast(lParam,KBDLLHOOKSTRUCT_p)
        
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值