[Function] GetKeyState isn't working! Please, help!

Get help with using AutoHotkey and its commands and hotkeys
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 27 Dec 2017, 12:40

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:17, edited 2 times in total.
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 18 Jan 2018, 12:50

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:17, edited 2 times in total.
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 19 Jan 2018, 15:19

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:18, edited 1 time in total.
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 20 Jan 2018, 23:23

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:18, edited 1 time in total.
User avatar
joedf
Posts: 6486
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Function] GetKeyState isn't working! Please, help!

Post by joedf » 21 Jan 2018, 00:20

why not use "D" instead of "P"?
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 22 Jan 2018, 10:30

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:18, edited 1 time in total.
User avatar
joedf
Posts: 6486
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Function] GetKeyState isn't working! Please, help!

Post by joedf » 22 Jan 2018, 11:34

Whats the point of 3ms wait times??
DllCall("Sleep","UInt",3) instead of sleep, 3... I imagine for shorter wait times.... is 10ms not enough?
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 22 Jan 2018, 13:33

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:18, edited 2 times in total.
User avatar
joedf
Posts: 6486
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Function] GetKeyState isn't working! Please, help!

Post by joedf » 22 Jan 2018, 22:01

Weird.... I tried the example, without the scroll-lock and everything works fine... :think:
Are you sure you're not running something else that might interfere?
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 23 Jan 2018, 09:48

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:18, edited 2 times in total.
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 23 Jan 2018, 10:01

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:18, edited 2 times in total.
Helgef
Posts: 3190
Joined: 17 Jul 2016, 01:02
Contact:

Re: [Function] GetKeyState isn't working! Please, help!

Post by Helgef » 23 Jan 2018, 13:05

Maybe try [docs]settimer[/docs],

Code: Select all

timerFn := func("pressKeys").bind([7,8,9], 4)

1::settimer, % timerFn, 0
1 up::settimer, % timerFn, off

pressKeys(keys, duration){
	for k, key in keys
		sendinput % "{" key " down}"
	sleep duration
	for k, key in keys
		sendinput % "{" key " up}"
}

esc::exitapp
cheers.
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 24 Jan 2018, 08:11

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:19, edited 1 time in total.
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 24 Jan 2018, 16:15

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:19, edited 2 times in total.
User avatar
joedf
Posts: 6486
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Function] GetKeyState isn't working! Please, help!

Post by joedf » 24 Jan 2018, 22:37

Should there be a % in front of duration
In your sleep?
Helgef
Posts: 3190
Joined: 17 Jul 2016, 01:02
Contact:

Re: [Function] GetKeyState isn't working! Please, help!

Post by Helgef » 25 Jan 2018, 04:35

Can you make it faster?
You can try this.

Code: Select all

pressKeys(keys, duration){
	loop 5 {
		for k, key in keys
			sendinput % "{" key " down}"
		dllcall("Sleep", "uint", duration)
		for k, key in keys
			sendinput % "{" key " up}"
	}
}
Faster doesn't necessarily mean better.
joedf wrote:Should there be a % in front of duration In your sleep?
Sleep's parameter can be an expression, hence, [docs]sleep[/docs] var is fine.
DllCall("Sleep","UInt",3) instead of sleep, 3.
Using dllcall("Sleep") can be more accurate. AHK's [docs]sleep[/docs] does something more fancy than just calling [url=https://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx]Sleep[/url]() for the full duration. As a consequence, we can start new threads, via messages, timers and hotkeys when a thread is sleeping. Example,

Code: Select all

ahkSleep := true
settimer a, -200
if ahkSleep
	sleep 4000
else
	dllcall("Sleep", "uint", 4000)
msgbox % "end of script"
return
a:
	msgbox % a_thislabel
return
The dllcall("Sleep") freezes the script, it is probably ok for short sleeps.

Cheers,
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 25 Jan 2018, 10:50

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:19, edited 2 times in total.
User avatar
Nextron
Posts: 1218
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

Re: [Function] GetKeyState isn't working! Please, help!

Post by Nextron » 25 Jan 2018, 12:50

Do you also get in an infinite loop if you remove all the lines above the hotkey? You could try to add a line to the hotkey, displaying a tooltip with A_Now and the result of GetKeyState, to see if it keeps updating the time after you release the key, or that there's just still a lot of keys coming out of the buffer, even though they shouldn't.
Helgef
Posts: 3190
Joined: 17 Jul 2016, 01:02
Contact:

Re: [Function] GetKeyState isn't working! Please, help!

Post by Helgef » 25 Jan 2018, 13:20

But even using loop 1
The higher loop x, the faster it will be.
Another version,

Code: Select all

#if GetKeyState("ScrollLock", "T")
1::
	do := true
	while do
		pressKeys([7,8,9], 1)
return
#if do
1 up::do := false

pressKeys(keys, duration){
	for k, key in keys
		sendinput % "{" key " down}"
	dllcall("Sleep", "uint", duration)
	for k, key in keys
		sendinput % "{" key " up}"
}
Rastahammer
Posts: 23
Joined: 17 Dec 2017, 13:09

Re: [Function] GetKeyState isn't working! Please, help!

Post by Rastahammer » 25 Jan 2018, 13:47

Solved.
Last edited by Rastahammer on 25 Jan 2018, 17:19, edited 2 times in total.
Post Reply

Return to “Ask For Help”