How to use the ahk.Control function in ahk

To help you get started, we’ve selected a few ahk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fx-kirin / pyahk / test / control.py View on Github external
def test_01_init(self):
        """Testing control initialization."""
        # Mock out script instance
        scr = mock.Mock(spec=self.script)
        # Set winExist return to known value
        def effect(title, *args, **kwargs):
            if 'error' in title.lower():
                return None
            return 42
        scr.winExist.side_effect = effect
        # First test no store and parameter set
        inparams = ('title', 'text', 'extitle', 'extext')
        ctl = ahk.Control(scr, *inparams, store=False)
        outparams = ctl._params() #NOTE use of private method could break!
        self.assertEqual(inparams, outparams,
            msg="Retrieved params {0} don't match input {1}!".format(
                outparams, inparams))
        # Next check HWND storage behavior
        with self.assertRaises(NameError):
            ctl = ahk.Control(scr, title='error') # store=True but window doesn't exist
        scr.reset_mock()
        ctl = ahk.Control(scr, *inparams)
        self.assertEqual(ctl.hwnd, 42, msg="Wrong HWND stored?")
        outparams = ctl._params() #NOTE use of private method could break!
        title = outparams[0].lower()
        self.assertTrue('ahk_id' in title and '42' in title,
            msg="HWND param \"{0}\" incorrectly formatted!".format(title))
        self.assertFalse(''.join(outparams[1:]), # Extra params are set to ''
            msg="Retrieved params {0} contain unexpected value!".format(
github fx-kirin / pyahk / test / control.py View on Github external
# Set winExist return to known value
        def effect(title, *args, **kwargs):
            if 'error' in title.lower():
                return None
            return 42
        scr.winExist.side_effect = effect
        # First test no store and parameter set
        inparams = ('title', 'text', 'extitle', 'extext')
        ctl = ahk.Control(scr, *inparams, store=False)
        outparams = ctl._params() #NOTE use of private method could break!
        self.assertEqual(inparams, outparams,
            msg="Retrieved params {0} don't match input {1}!".format(
                outparams, inparams))
        # Next check HWND storage behavior
        with self.assertRaises(NameError):
            ctl = ahk.Control(scr, title='error') # store=True but window doesn't exist
        scr.reset_mock()
        ctl = ahk.Control(scr, *inparams)
        self.assertEqual(ctl.hwnd, 42, msg="Wrong HWND stored?")
        outparams = ctl._params() #NOTE use of private method could break!
        title = outparams[0].lower()
        self.assertTrue('ahk_id' in title and '42' in title,
            msg="HWND param \"{0}\" incorrectly formatted!".format(title))
        self.assertFalse(''.join(outparams[1:]), # Extra params are set to ''
            msg="Retrieved params {0} contain unexpected value!".format(
                outparams[1:]))
github fx-kirin / pyahk / test / control.py View on Github external
if 'error' in title.lower():
                return None
            return 42
        scr.winExist.side_effect = effect
        # First test no store and parameter set
        inparams = ('title', 'text', 'extitle', 'extext')
        ctl = ahk.Control(scr, *inparams, store=False)
        outparams = ctl._params() #NOTE use of private method could break!
        self.assertEqual(inparams, outparams,
            msg="Retrieved params {0} don't match input {1}!".format(
                outparams, inparams))
        # Next check HWND storage behavior
        with self.assertRaises(NameError):
            ctl = ahk.Control(scr, title='error') # store=True but window doesn't exist
        scr.reset_mock()
        ctl = ahk.Control(scr, *inparams)
        self.assertEqual(ctl.hwnd, 42, msg="Wrong HWND stored?")
        outparams = ctl._params() #NOTE use of private method could break!
        title = outparams[0].lower()
        self.assertTrue('ahk_id' in title and '42' in title,
            msg="HWND param \"{0}\" incorrectly formatted!".format(title))
        self.assertFalse(''.join(outparams[1:]), # Extra params are set to ''
            msg="Retrieved params {0} contain unexpected value!".format(
                outparams[1:]))
github fx-kirin / pyahk / test / control.py View on Github external
def test_00_delay(self):
        """Testing control delay decorator."""
        ctl = ahk.Control(self.script, store=False)
        # Set the control delay and check that it is set
        delay = 50
        ctl.set_delay(control=delay)
        self.assertEqual(ctl._cdelay, delay, msg="Set delay not stored?")
        # Mock out ahk.execute in the control module so no commands actually run
        with mock.patch('ahk.control.execute') as exc:
            outer_delay = ahk.get("A_ControlDelay")
            inner_delay = list() # Object in outer scope
            def store(cmd):
                """execute replacement for mock."""
                # Object in outer scope used in closure to store a value
                inner_delay.append(int(ahk.get("A_ControlDelay")))
                if 'send' not in cmd.lower():
                    #print cmd, inner_delay
                    ahk.execute(cmd)