So i was wondering if there was a way to automatically put characters before text and before you press enter, so say you typed "Hello", it would come out /Hello/after you pressed enter.
Thanks, any help would be appreciated.
Putting characters before and after text Topic is solved
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Putting characters before and after text Topic is solved
Hi nijwons,
I see that you joined our group today and that this is your first post, so let me start by saying...Welcome Aboard!
I'm not an expert in hotkeys and hotstrings, so there may be a much better way to do this, but my first thought is to define every key on the keyboard that produces a character as a hotstring that appends itself to a current-text string and then sends itself. At the end, the Enter key (via a hotkey, not hotstring) sends the current-text string, prefixed and suffixed by the specified characters, and resets the current-text string to null.
Here's the beginning of such a script to get you going:
To show the method, I've included hotstrings for the upper and lower case letter A, number 0, space, a few special chars (<, >, /, and \), and, of course, the hotkey for the Enter key.
You'll have to expand the script to include all upper and lower case letters, all numbers, and all special chars. Note that c in the hotstring means that it is case sensitive and * in the hotstring means that an ending character is not required to trigger it. Also, note that ~ in the Enter hotkey means that its native function will not be blocked when it fires. Regards, Joe
I see that you joined our group today and that this is your first post, so let me start by saying...Welcome Aboard!
I'm not an expert in hotkeys and hotstrings, so there may be a much better way to do this, but my first thought is to define every key on the keyboard that produces a character as a hotstring that appends itself to a current-text string and then sends itself. At the end, the Enter key (via a hotkey, not hotstring) sends the current-text string, prefixed and suffixed by the specified characters, and resets the current-text string to null.
Here's the beginning of such a script to get you going:
Code: Select all
#Warn,UseUnsetLocal ; warn when local variable is used before it is set
#NoEnv ; do not check empty variables to see if they are environment variables
#SingleInstance Force ; skip dialog box and replace old instance immediately
SetBatchLines,-1 ; run at maximum speed
SendMode Input ; generally faster and more reliable
BeforeTextChar:="<" ; change this to whatever you want
AfterTextChar:=">" ; change this to whatever you want
CurrentText:=""
:c*:a::
CurrentText:=CurrentText . "a"
Send a
Return
:c*:A::
CurrentText:=CurrentText . "A"
Send A
Return
:*:0::
CurrentText:=CurrentText . "0"
Send 0
Return
:*: ::
CurrentText:=CurrentText . A_Space
Send %A_Space%
Return
:*:<::
CurrentText:=CurrentText . "<"
Send <
Return
:*:>::
CurrentText:=CurrentText . ">"
Send >
Return
:*:/::
CurrentText:=CurrentText . "/"
Send /
Return
:*:\::
CurrentText:=CurrentText . "\"
Send \
Return
~Enter::
CurrentText:=BeforeTextChar . CurrentText . AfterTextChar
Send %CurrentText%{Enter}
CurrentText:=""
Return
You'll have to expand the script to include all upper and lower case letters, all numbers, and all special chars. Note that c in the hotstring means that it is case sensitive and * in the hotstring means that an ending character is not required to trigger it. Also, note that ~ in the Enter hotkey means that its native function will not be blocked when it fires. Regards, Joe
Re: Putting characters before and after text
My idea is similar to Joe's, but does what the TooltipKeypress script does and creates hotkeys for each key programatically:
That appears to do what it sounds like you're asking for.
Code: Select all
Loop, 5000
{
Hotkey, % "~*" GetKeyName(Format("vk{:x}", a_index - 1)), GetText ; Create lowercase hotkeys
Hotkey, % "~*+" GetKeyName(Format("vk{:x}", a_index - 1)), GetText ; Create uppercase hotkeys
}
GetText:
Sleep, 50
Key := SubStr(A_ThisHotkey, 3) ; Remove the first 2 characters ("~*") from the returned string
If(SubStr(Key, 1, 1) = "+")
Text .= Format("{:U}", SubStr(Key, 2, 1)) ; Convert the 2nd character (after the "+") to uppercase
Else If(StrLen(Key) = 1)
Text .= Key
Else If(Key = "Enter")
{
NumBack := StrLen(Text) + 1 ; Backspace the length of the string + 1 for Enter
Send, {Backspace %NumBack%}/%Text%/
NumBack := 0
Text := ""
}
Return
Last edited by Osprey on 14 Apr 2019, 17:05, edited 3 times in total.
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Putting characters before and after text
> creates hotkeys for each key programatically
Great idea, Osprey! Regards, Joe
Great idea, Osprey! Regards, Joe
Re: Putting characters before and after text
Thank you so much, is there way to return the string as you press enter, so that when you sent a message it would send it as /Hello/? Sorry if this is vaguely worded, im not sure how to word it well. Again, thank you so much for the answer!
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Putting characters before and after text
> is there way to return the string as you press enter, so that when you sent a message it would send it as /Hello/
That's what my script does. When you press Enter, it executes this command:
The CurrentText variable has the text that you entered, prefixed by the BeforeTextChar character and suffixed by the AfterTextChar character (in your case, you want both to be a forward slash - / - but I made them variables so that the solution is more general). Regards, Joe
That's what my script does. When you press Enter, it executes this command:
Code: Select all
Send %CurrentText%{Enter}
Re: Putting characters before and after text
Yeah, I've tried it but when running the script I cannot type characters, nothing happens.
Thanks.
Thanks.
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Putting characters before and after text
Works perfectly here...I tested it well before posting. Please post the full script that you're using.
Re: Putting characters before and after text
Wait sorry, my bad, figured it out!
Re: Putting characters before and after text
Wait sorry, my bad, figured it out!
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Putting characters before and after text
Great news!
Re: Putting characters before and after text
Is it possible to the before text above the CurrentText and the AfterText below the CurrentText, sorry, I'm new to AHK, trying to figure it out and you've been a huge help, thank you!
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Putting characters before and after text
Not sure I understand...do you mean that you want this:
/
Hello
/
If so, then simply put a new line character - `n - before and after CurrentText. In other words, change the assignment statement in the Enter hotkey to this:
If that's not what you want, please explain in more detail. Regards, Joe
/
Hello
/
If so, then simply put a new line character - `n - before and after CurrentText. In other words, change the assignment statement in the Enter hotkey to this:
Code: Select all
CurrentText:=BeforeTextChar . "`n" . CurrentText . "`n" . AfterTextChar
Last edited by JoeWinograd on 15 Apr 2019, 13:04, edited 1 time in total.
Re: Putting characters before and after text
Yes, thank you.
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Putting characters before and after text
Our messages just crossed. See the update to my previous post.
Re: Putting characters before and after text
Thank you so much!
- JoeWinograd
- Posts: 2203
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Putting characters before and after text
You're very welcome!
Re: Putting characters before and after text
Hey, I know this is a very late followup, but is there a way to send them all in one message instead of 3? Currently it sends / then hello then / instead of them all in the same message on different lines
Thanks.
Thanks.
Who is online
Users browsing this forum: No registered users and 145 guests