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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rastahammer
Posts: 22
Joined: 17 Dec 2017, 13:09

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

27 Dec 2017, 12:40

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

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

18 Jan 2018, 12:50

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

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

19 Jan 2018, 15:19

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

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

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: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

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

21 Jan 2018, 00:20

why not use "D" instead of "P"?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Rastahammer
Posts: 22
Joined: 17 Dec 2017, 13:09

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

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: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

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

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?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Rastahammer
Posts: 22
Joined: 17 Dec 2017, 13:09

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

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: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

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

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?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Rastahammer
Posts: 22
Joined: 17 Dec 2017, 13:09

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

23 Jan 2018, 09:48

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

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

23 Jan 2018, 10:01

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

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

23 Jan 2018, 13:05

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.
Rastahammer
Posts: 22
Joined: 17 Dec 2017, 13:09

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

24 Jan 2018, 08:11

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

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

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: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

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

24 Jan 2018, 22:37

Should there be a % in front of duration
In your sleep?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

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

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, 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,
Rastahammer
Posts: 22
Joined: 17 Dec 2017, 13:09

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

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: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

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

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: 4709
Joined: 17 Jul 2016, 01:02
Contact:

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

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: 22
Joined: 17 Dec 2017, 13:09

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

25 Jan 2018, 13:47

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], OrangeCat and 126 guests