允许自定义组合和关键字触发自定义函数的键盘侦听器

keyboard-listener的Python项目详细描述


键盘监听程序

键盘侦听器是一个模块,允许您创建自定义热键(组合)或自定义关键字,并将它们绑定到Python中的自定义函数。它非常容易使用,可以通过pip安装:

pip install keyboard_listener

组合是绑定到函数的自定义热键。当按下组合键时,执行该功能。组合非常容易设置,可以在下面的示例中看到。在

Keywords是自定义字符串,当输入(或者更确切地说,当它们的字符按顺序输入时)将触发要执行的函数。关键字也显示在下面的示例中。在

在运行之前,KeyboardListener对象需要用自定义组合和自定义关键字词典实例化。请参考下面的示例以了解如何设置这些。如果没有传递字典,程序将假定没有设置组合或关键字。在

示例:

fromkeyboard_listenerimportKeyboardListener,Combo,KeyWorddeffunction_1(arguments):# do somethingdeffunction_2(arguments):# do something elsecombinations={'function 1':Combo(['alt'],'f',function_1,arguments),#Function 1 is executed when the user presses Alt+F'function 2':Combo(['ctr','alt'],'g',function_2,arguments),#Function 2 is executed when the user presses Alt+G'function 3':Combo(['shift','alt'],'H',function_2,arguments),#Be mindful when setting up Combos that include 'shift'. If the Combo includes the shift key, the character must be uppercase.}keywords={'keyword_1':KeyWord('keyword1',function_1,arguments),#Function 1 is executed when the user types 'keyword1''keyword_2':KeyWord('keyword1',function_2,arguments)#Function 2 is executed when the user types 'keyword2'}keyboard_listener=KeyboardListener(combinations=combinations,keywords=keywords)keyboard_listener.run()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java既然Lucene 4.1中不存在TermEnum,如何从IndexReader中获取字段?   java在LinkedHashSet上的迭代比在ArrayList上的迭代要快   java无法在Android Studio中获得所有@override函数,如onStart、onResume   java的DateTimeFormatter比SimpleDateFormat更严格吗?以毫秒为单位分析日期   JavaSpring*servlet。Websphere服务器启动时未加载xml   java Fancytree selenium单击事件   java日期格式不一样   java无法在Android Studio上运行我的MQTT应用程序   c#计算两个集合的F检验   java JDialog不会显示在“设计”选项卡中   java如何在每个服务生页面上重新加载页面   java如何初始化包含一些对象的数组?   使用Datanucleus的java Amazon S3数据存储   Python的map函数是否有Java等价物?