ConsoleSend and Control Chars

Get help with using AutoHotkey and its commands and hotkeys
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

ConsoleSend and Control Chars

07 Nov 2013, 01:39

am i correct to assume that in the following (spoiler :lol:) script, text cannot be control characters (such as ^j)? :ugeek: P.S.: how can the function be modified so that it CAN accept control chars? :?
ConsoleSend("^j", WinTitle="", WinText="", ExcludeTitle="", ExcludeText="")
Spoiler
User avatar
joedf
Posts: 7898
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ConsoleSend and Control Chars

07 Nov 2013, 12:42

Yes (I think :P ) also, Check out LibCon.ahk in my signature ;)
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: ConsoleSend and Control Chars

07 Nov 2013, 14:39

it says, "Currently ConsoleSend accepts literal text only. Adapting it to send unicode characters or control characters is a possibility." :ugeek:
User avatar
joedf
Posts: 7898
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ConsoleSend and Control Chars

07 Nov 2013, 15:05

Well LibCon supports Unicode, I could also add control characters in the near future.. ;)
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: ConsoleSend and Control Chars

07 Nov 2013, 18:25

i'm currently looking for a robust replacement for ControlSend. an ability to use control characters is my humble request. :ugeek:
joedf wrote:Well LibCon supports Unicode, I could also add control characters in the near future.. ;)
User avatar
joedf
Posts: 7898
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ConsoleSend and Control Chars

08 Nov 2013, 17:58

haha i think i got it :P so much simpler too :D

Code: Select all

Run,%comspec%,,,cPID
WinWaitActive, % (cmd := "ahk_pid " cPID)
ConsoleSend_joedf("echo Beep: {Ctrl Down}g{Ctrl Up}{Enter}",cmd)

ConsoleSend_joedf(keys, WinTitle="") {
	ControlFocus,,%WinTitle%
	if ErrorLevel
		return 0
	SendInput %keys% ;SendInput {Raw}%text%
	return 1
}
regards ;)
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: ConsoleSend and Control Chars

08 Nov 2013, 20:54

great work! can this be modified so that i can send "Control Char + Proper Char" :lol: (in lieu of ControlSend) to an open Excel spreadsheet (as a macro shortcut to Excel proper) such as ^j? :ugeek:
joedf wrote:haha i think i got it :P so much simpler too :D

Code: Select all

Run,%comspec%,,,cPID
WinWaitActive, % (cmd := "ahk_pid " cPID)
ConsoleSend_joedf("echo Beep: {Ctrl Down}g{Ctrl Up}{Enter}",cmd)

ConsoleSend_joedf(keys, WinTitle="") {
	ControlFocus,,%WinTitle%
	if ErrorLevel
		return 0
	SendInput %keys% ;SendInput {Raw}%text%
	return 1
}
regards ;)
User avatar
joedf
Posts: 7898
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ConsoleSend and Control Chars

09 Nov 2013, 13:51

you mean? in console, when you press ^j it will launch Excel?
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: ConsoleSend and Control Chars

09 Nov 2013, 15:16

i think i have belatedly come to understand that ConsoleSend and its variations are designed for Console ONLY and it is NOT possible to write a command using ConsoleSend or its variations in an effort to replace "ControlSend, , {Ctrl Down}j{Ctrl Up}, Excel_Spreadsheet" to send "Control Char + Proper Char" to any other Control or Window other than a Console. :o
joedf wrote:you mean? in console, when you press ^j it will launch Excel?
User avatar
joedf
Posts: 7898
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ConsoleSend and Control Chars

09 Nov 2013, 17:29

well you are correctly but my version should work with excel...
this does not work? (you want to avoid it?) : ControlSend, , {Ctrl Down}j{Ctrl Up}, Excel_Spreadsheet
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: ConsoleSend and Control Chars

09 Nov 2013, 17:56

"{Ctrl Down}j{Ctrl Up}, Excel_Spreadsheet" sometimes actually enters a real "j" in a cell (undesired since i intend to send ^j as a macro command to the spreadsheet).... :(
so what would be your version to send "^j" as an equivalent of "{Ctrl Down}j{Ctrl Up}, Excel_Spreadsheet"? :ugeek:
joedf wrote:well you are correctly but my version should work with excel...
this does not work? (you want to avoid it?) : ControlSend, , {Ctrl Down}j{Ctrl Up}, Excel_Spreadsheet
User avatar
joedf
Posts: 7898
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ConsoleSend and Control Chars

09 Nov 2013, 18:40

try this???

Code: Select all

sendInput {Ctrl Down}
sleep 50
sendInput j
sleep 50
sendInput {Ctrl Up}
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: ConsoleSend and Control Chars

09 Nov 2013, 19:39

i have previously tried SetKeyDelay and similar approaches in vain. but i'll try this one (specially, the SendInput part). ;) i plan to use it in the following way:
ControlFocus, XLDESK1, Excel_Spreadsheet
SendInput {Ctrl Down}
Sleep 50
SendInput j
Sleep 50
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: ConsoleSend and Control Chars

19 Nov 2013, 14:21

none of the above tricks worked! i believe i found this definitive cure to prevent entering char "j" in the target cell "M1": :ugeek:

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)

Dim TestCell
Dim RE As Object
Dim REMatches As Object

Set RE = CreateObject("vbscript.regexp")
With RE
    .MultiLine = False
    .Global = False
    .IgnoreCase = True
    .Pattern = "[j,]"
End With

For Each TestCell In Range("M1")
    Set REMatches = RE.Execute(TestCell.Value)
    If REMatches.Count > 0 Then
        'MsgBox "Invalid:" & TestCell.Address & "-" & TestCell.Value
        TestCell.Value = ""
    End If
Next

End Sub
User avatar
joedf
Posts: 7898
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ConsoleSend and Control Chars

19 Nov 2013, 18:07

Cool :)
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: ConsoleSend and Control Chars

19 Nov 2013, 18:19

joedf wrote:Cool :)
actually this is a modified version. i customized it for my own script. :lol: the original version was: :ugeek:

...
.Pattern = "[^0-9A-Z,]"
...
For Each TestCell In Target.Cells
...

Return to “Ask For Help”

Who is online

Users browsing this forum: Arsonistic, mikeyww, nacken012, newbieforever, paul1965 and 50 guests