Need a Little Help for creating Script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
noobgraphicartist
Posts: 59
Joined: 12 Jan 2015, 18:36

Need a Little Help for creating Script

21 Apr 2017, 07:14

i need a little help creating a complicated script
basically i want to create a script like this

example
if i press letter 'W' then it will send W
but when I hit W again for the second time , it will not send or do anything because
the last previous keyboard pressed is 'W'

more clarification or example
you cannot type
WWHEAT , WWAR

ps : If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 400)
i really dont want to use this command

i hope someone can help :(
Last edited by noobgraphicartist on 21 Apr 2017, 07:33, edited 1 time in total.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Need a Little Help for creating Script

21 Apr 2017, 07:32

Not sure what you are trying to accomplish, but:

Code: Select all

:*:WW::W
turns WW into W when you type it.
noobgraphicartist
Posts: 59
Joined: 12 Jan 2015, 18:36

Re: Need a Little Help for creating Script

21 Apr 2017, 07:37

WalkerOfTheDay wrote:Not sure what you are trying to accomplish, but:

Code: Select all

:*:WW::W
turns WW into W when you type it.
thanks for fast reply
sadly this is not im looking for

to elaborate more
i am going to use the script mainly for Zbrush

in Zbrush when i assigned W as keyboard shortcut key for ZADD
the function is toggling in cycle mode ( ON / OFF)
which i really dont want

i want to disable the OFF

so i come up with the idea and dont know if its possible in AHK

if i press letter 'W' then it will send W
but when I hit W again for the second time , it will not send or do anything because
the last previous keyboard pressed is 'W'
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Need a Little Help for creating Script

21 Apr 2017, 14:51

I have a few ideas that might be useful:

The hotkeys may interfere with hotstrings.

This prevents any letter, or its capital being repeated.

Code: Select all

Hotkey, IfWinActive, ahk_class Notepad
Loop, 26
{
	Hotkey, % "$" Chr(96+A_Index), MyLabel
	Hotkey, % "$+" Chr(96+A_Index), MyLabel
}
return

MyLabel:
vLetter := SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
if !(vLetter = vLetterLast)
	if InStr(A_ThisHotkey, "+")
		SendInput, % "+" vLetter
	else
		SendInput, % vLetter
vLetterLast := SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
return
This prevents w, or its capital being repeated. If any of q/e/r/t/y is pressed, they work as normal, but allow w to be pressed once more, although you will still not be able to repeat w.

Code: Select all

~q::
~e::
~r::
~t::
~y::
vLetterLast := SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
return

$w::
vLetter := SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
if !(vLetter = vLetterLast)
	SendInput, % vLetter
vLetterLast := SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
return
Based on the problem you described, something like this may be desirable. You can only press w once per window, although if the window title changes, you will be able to press w once more.

Code: Select all

$w::
WinGet, hWnd, ID, A
WinGetTitle, vWinTitle, % "ahk_id " hWnd
if !vWinListBlock
	vWinListBlock := "`n"
if !InStr(vWinListBlock, "`n" hWnd "`t" vWinTitle "`n")
{
	SendInput w
	vWinListBlock .= hWnd "`t" vWinTitle "`n"
}
return
More simply, you can only press w once per window.

Code: Select all

$w::
WinGet, hWnd, ID, A
if !vWinListBlock
	vWinListBlock := ","
if !InStr(vWinListBlock, "," hWnd ",")
{
	SendInput w
	vWinListBlock .= hWnd ","
}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 261 guests