0

在 Python IDLE 中执行以 Leap-Motion 为中心的代码时,切换到另一个窗口会使 IDLE 忽略 Leap 控制器并停止处理frames。如何避免这种情况,例如,Leap 手势可以用于与其他窗口进行交互?

不是很相关,但重现此问题的代码:

import Leap
from Leap import *

class FocusListener(Leap.Listener):
    def on_frame(self, controller):
        frame = controller.frame()
        print frame

def main():
    # Create a sample listener and controller
    listener = FocusListener()
    controller = Leap.Controller()

    controller.add_listener(listener)

    while (1):
        listener.on_frame(controller)


if __name__ == "__main__":
    main()

PS:这可能与我“综合地”用 循环框架的事实有关while吗?

4

1 回答 1

1

要在您的应用没有聚焦时获取帧,您需要设置“背景帧”策略:

controller.set_policy_flags(Leap.Controller.POLICY_BACKGROUND_FRAMES);

见:https ://developer.leapmotion.com/documentation/python/api/Leap.Controller.html#Leap.Controller.set_policy_flags

于 2014-03-03T23:34:07.017 回答