Exemplo n.º 1
0
    def test_3(self):
        start = time.time()
        macro = parse('r(3, k(m).w(100))', self.mapping)
        m_code = system_mapping.get('m')
        self.assertSetEqual(macro.get_capabilities()[EV_KEY], {m_code})
        self.loop.run_until_complete(macro.run(self.handler))

        keystroke_time = 6 * self.mapping.get('macros.keystroke_sleep_ms')
        total_time = keystroke_time + 300
        total_time /= 1000

        self.assertGreater(time.time() - start, total_time * 0.9)
        self.assertLess(time.time() - start, total_time * 1.1)
        self.assertListEqual(self.result, [
            (EV_KEY, m_code, 1),
            (EV_KEY, m_code, 0),
            (EV_KEY, m_code, 1),
            (EV_KEY, m_code, 0),
            (EV_KEY, m_code, 1),
            (EV_KEY, m_code, 0),
        ])
        self.assertEqual(len(macro.child_macros), 1)
        self.assertEqual(len(macro.child_macros[0].child_macros), 0)
Exemplo n.º 2
0
    def test_hold(self):
        macro = parse('k(1).h(k(a)).k(3)', self.mapping)
        macro.set_handler(self.handler)
        self.assertSetEqual(
            macro.get_capabilities(), {
                system_mapping.get('1'),
                system_mapping.get('a'),
                system_mapping.get('3')
            })

        macro.press_key()
        asyncio.ensure_future(macro.run())
        self.loop.run_until_complete(asyncio.sleep(0.2))
        macro.release_key()
        self.loop.run_until_complete(asyncio.sleep(0.05))

        self.assertEqual(self.result[0], (system_mapping.get('1'), 1))
        self.assertEqual(self.result[-1], (system_mapping.get('3'), 0))

        code_a = system_mapping.get('a')
        self.assertGreater(self.result.count((code_a, 1)), 2)

        self.assertEqual(len(macro.child_macros), 1)
Exemplo n.º 3
0
    def test_run_plus_syntax(self):
        macro = parse('a + b + c + d', self.mapping)
        self.assertSetEqual(
            macro.get_capabilities()[EV_KEY], {
                system_mapping.get('a'),
                system_mapping.get('b'),
                system_mapping.get('c'),
                system_mapping.get('d')
            })

        macro.press_key()
        asyncio.ensure_future(macro.run(self.handler))
        self.loop.run_until_complete(asyncio.sleep(0.2))
        self.assertTrue(macro.is_holding())

        # starting from the left, presses each one down
        self.assertEqual(self.result[0], (EV_KEY, system_mapping.get('a'), 1))
        self.assertEqual(self.result[1], (EV_KEY, system_mapping.get('b'), 1))
        self.assertEqual(self.result[2], (EV_KEY, system_mapping.get('c'), 1))
        self.assertEqual(self.result[3], (EV_KEY, system_mapping.get('d'), 1))

        # and then releases starting with the previously pressed key
        macro.release_key()
        self.loop.run_until_complete(asyncio.sleep(0.2))
        self.assertFalse(macro.is_holding())
        self.assertEqual(self.result[4], (EV_KEY, system_mapping.get('d'), 0))
        self.assertEqual(self.result[5], (EV_KEY, system_mapping.get('c'), 0))
        self.assertEqual(self.result[6], (EV_KEY, system_mapping.get('b'), 0))
        self.assertEqual(self.result[7], (EV_KEY, system_mapping.get('a'), 0))