Conditional hotstring? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Conditional hotstring?

17 Mar 2018, 13:22

Is this possible?

I want
::imo::In my opinion,

To function if enter was the last button pressed. (excluding when imo was typed)

Or else I want

::imo::in my opinion.

To function.


So how would you go about doing this? The if enter was pressed part? Can you give me an example script for that I appreciate it thanks.
I'm guessing it will need a loop to check if enter was pressed, and something that would wait for more than three characters to be typed?
I am your average ahk newbie. Just.. a tat more cute. ;)
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Conditional hotstring?

17 Mar 2018, 14:35

Code: Select all

:X:imo::sendinput % "in my opinion" . (a_endchar == "`n" ? "," : ".")
Cheers
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Conditional hotstring?

17 Mar 2018, 14:46

Someone can explain me why this does not work

Code: Select all

:X:imo::sendinput % "in my opinion" . (a_endchar == "`n" ? "," : ".")
it writes
sendinput % "in my opinion" . (a_endchar == "
" ? "," : ".")
... while this works

Code: Select all

:X:imo::
	sendinput % "in my opinion" . (a_endchar == "`n" ? "," : ".")
return
it writes
in my opinion. ; with any key
in my opinion, ; with enter
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Conditional hotstring?

17 Mar 2018, 14:50

your signature wrote:Autohotkey v1.1.24.02 64-bit Unicode
Update ;). X option is new.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Conditional hotstring?

17 Mar 2018, 14:53

@Helgef THX.
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Conditional hotstring?

17 Mar 2018, 22:42

Helgef wrote:

Code: Select all

:X:imo::sendinput % "in my opinion" . (a_endchar == "`n" ? "," : ".")
Cheers
Woah thanks a lot that's really useful.

However that is not what I meant. In your script, it sends out ',' or '.' depending on which end character was used to trigger the hotstring.
But what I want, is if the {enter} button was pressed right before the hotstring is typed, that it says In my opinion, instead of in my opinion. Also notice that there is an uppercase. Is this possible?
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Conditional hotstring?  Topic is solved

17 Mar 2018, 23:53

Perhaps something like this:

Code: Select all

:B0C:`nImo::
SendInput, {Backspace 3}n my opinion,
return

::imo::in my opinion.
The C option can be helpful for specifying the case of the trigger, and SendInput can be helpful for specifying the case of the output string.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Conditional hotstring?

18 Mar 2018, 01:35

jeeswg wrote:Perhaps something like this:

Code: Select all

:B0C:`nImo::
SendInput, {Backspace 3}n my opinion,
return

::imo::in my opinion.
The C option can be helpful for specifying the case of the trigger, and SendInput can be helpful for specifying the case of the output string.
Thanks I totally forgot about `n!!! You're an angel! This made it so much less complex.
Do you have list for other keys like tab and shift?
I am your average ahk newbie. Just.. a tat more cute. ;)
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: Conditional hotstring?

18 Mar 2018, 02:16

Nwb wrote:Do you have list for other keys like tab and shift?
These are rather different things, `n is not a key. Here you can find escape sequences: https://autohotkey.com/docs/commands/_EscapeChar.htm Hotkey modifiers like 'shift' on the other hand: https://autohotkey.com/docs/Hotkeys.htm#Symbols
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Conditional hotstring?

18 Mar 2018, 03:06

gregster wrote:
Nwb wrote:Do you have list for other keys like tab and shift?
These are rather different things, `n is not a key. Here you can find escape sequences: https://autohotkey.com/docs/commands/_EscapeChar.htm Hotkey modifiers like 'shift' on the other hand: https://autohotkey.com/docs/Hotkeys.htm#Symbols
Thanks precisely what I wanted!
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Conditional hotstring?

18 Mar 2018, 08:18

- Not every key can be used as a hotstring, for tab you can use `t. For shift, sometimes you can specify the key that you would get when you hold down shift, shift+a -> A, shift+1 -> !.

Code: Select all

:*:!abc::def
:*:`tabc::ghi
- I did make a suggestion that AutoHotkey could add support for all keys within hotstrings (classic 'easier said than done'), workarounds would be to use the Input command, or to add ~ (tilde) hotkeys for every key, that reset A_PriorKey (and check the value of A_PriorKey within the code for the hotstring).
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: Anput, arcylix, drani, Google [Bot], Rohwedder and 208 guests