Page 2 of 3

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

Posted: 27 Dec 2017, 12:40
by Rastahammer
Solved.

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

Posted: 18 Jan 2018, 12:50
by Rastahammer
Solved.

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

Posted: 19 Jan 2018, 15:19
by Rastahammer
Solved.

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

Posted: 20 Jan 2018, 23:23
by Rastahammer
Solved.

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

Posted: 21 Jan 2018, 00:20
by joedf
why not use "D" instead of "P"?

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

Posted: 22 Jan 2018, 10:30
by Rastahammer
Solved.

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

Posted: 22 Jan 2018, 11:34
by joedf
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?

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

Posted: 22 Jan 2018, 13:33
by Rastahammer
Solved.

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

Posted: 22 Jan 2018, 22:01
by joedf
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?

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

Posted: 23 Jan 2018, 09:48
by Rastahammer
Solved.

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

Posted: 23 Jan 2018, 10:01
by Rastahammer
Solved.

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

Posted: 23 Jan 2018, 13:05
by Helgef
Maybe try settimer,

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.

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

Posted: 24 Jan 2018, 08:11
by Rastahammer
Solved.

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

Posted: 24 Jan 2018, 16:15
by Rastahammer
Solved.

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

Posted: 24 Jan 2018, 22:37
by joedf
Should there be a % in front of duration
In your sleep?

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

Posted: 25 Jan 2018, 04:35
by Helgef
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, sleep var is fine.
DllCall("Sleep","UInt",3) instead of sleep, 3.
Using dllcall("Sleep") can be more accurate. AHK's sleep does something more fancy than just calling Sleep() 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,

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

Posted: 25 Jan 2018, 10:50
by Rastahammer
Solved.

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

Posted: 25 Jan 2018, 12:50
by Nextron
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.

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

Posted: 25 Jan 2018, 13:20
by Helgef
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}"
}

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

Posted: 25 Jan 2018, 13:47
by Rastahammer
Solved.