dodger42 Posted July 30, 2006 Share Posted July 30, 2006 Hey all, I just put together some basic code to send messages to a flightsim. expandcollapse popupOpt("WinWaitDelay",100) Opt("WinTitleMatchMode",4) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) If $CmdLine[0] = 0 Then MsgBox(0, "Usage", "lockonmsg.exe /t (team) or /a (all) message") ElseIf $CmdLine[1] = "/?" Then MsgBox(0, "Usage", "lockonmsg.exe /t (team) or /a (all) message") ElseIf $CmdLine[1] = "/ver" Then MsgBox(0, "Version", "v0.94") ElseIf $CmdLine[1] = "/a" Then $msg1 = "{CTRLDOWN}m{CTRLUP}" _ActiveLockon() Sleep(1000) Send($msg1) Sleep(500) Send($CmdLine[2], 1) Sleep(100) Send("{ENTER}") Sleep(100) Send($msg1) ElseIf $CmdLine[1] = "/t" Then $msg1 = "{ALTDOWN}m{ALTUP}" _ActiveLockon() Sleep(1000) Send($msg1) Sleep(500) Send($CmdLine[2], 1) Sleep(100) Send("{ENTER}") Sleep(100) Send($msg1) ElseIf $CmdLine[1] = "/stat" Then $LockonPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Ubisoft\Eagle Dynamics\Lock On", "Path") ;MsgBox(0, "LockonPath", "= " & $LockonPath) $ExportDir = "\temp\" $ExportFile = ($LockonPath & $ExportDir &"export.log") ;MsgBox(0, "Export File", "= " & $File) $Lines = _FileCountLines($ExportFile) ;MsgBox(0, "Lines", "Export has: " & $Lines) $Readline = $Lines - 1 ;Get Stat line from LUA export log $file = FileOpen($ExportFile, 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $line = FileReadLine($file, $Readline) FileClose($file) MsgBox(0, "Lines", "Line is: " & $line) $msg1 = "{ALTDOWN}m{ALTUP}" ;$msg2 = $CmdLine[2] _ActiveLockon() ;Send("{CTRLDOWN}m{CTRLUP}blah{ENTER}{CTRLDOWN}m{CTRLUP}") Sleep(1000) Send($msg1) Sleep(500) Send($line,1) Sleep(1000) Send("{ENTER}") Sleep(500) Send($msg1) EndIf Func _FileCountLines($sFilePath) Local $N = FileGetSize($sFilePath) - 1 If @error Or $N = -1 Then Return 0 Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1 EndFunc Func _ActiveLockon() If Not WinExists("LOCK ON","") Then MsgBox(0, "Error", "Lockon is not running") If Not WinActive("LOCK ON","") Then WinActivate("LOCK ON","") WinWaitActive("LOCK ON","") Sleep(2000) EndFunc Func _CheckMessage($var) If $var = "" Then MsgBox(0, "Error", "No Message. Check usage with /? flag") Exit EndFunc Every time I run it though, I get different results. Quite often it sends the message ok. Then the next run with the exact same command, only executes part of the command. It seems quite sensitive to the Sleep commands, and wondering if anybody could advise if this (my first real AutoIT script) is missing something. Link to comment Share on other sites More sharing options...
nfwu Posted July 30, 2006 Share Posted July 30, 2006 If you are sending keys, try putting: BlockInput(1) before and BlockInput(0) after to prevent user input from distrupting the SendKey process. #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
dodger42 Posted July 31, 2006 Author Share Posted July 31, 2006 If you are sending keys, try putting:BlockInput(1)before and BlockInput(0)after to prevent user input from distrupting the SendKey process.#)Thanks that helped. I cleaned up a lot of the repetitive code as well, and threw most of the stuff into functions, it seems more reliable so far, but still one or two anomolies. Link to comment Share on other sites More sharing options...
dodger42 Posted July 31, 2006 Author Share Posted July 31, 2006 (edited) Thanks that helped. I cleaned up a lot of the repetitive code as well, and threw most of the stuff into functions, it seems more reliable so far, but still one or two anomolies. I created this function: Func _LockonSend($msg1,$msg2) _ActiveLockon() BlockInput(1) Send($msg1) Sleep(500) Send($msg2, 1) Sleep(100) Send("{ENTER}") Send($msg1) BlockInput(0) EndFunc $msg2 may include special characters. I'm certain this is screwing the system. For example, a typical line will look like this: $msg2 = ALT = 32, IAS(kn) = 0, IAS(kmh) = 0, Hdg = 357 I added the ,1 flag to send it raw, but I think its not getting the necessary "". How would I go about encapsulating $msg with quotes? e.g., something like $msg2 = "\""& $msg2 & "\"" Edited July 31, 2006 by dodger42 Link to comment Share on other sites More sharing options...
dodger42 Posted July 31, 2006 Author Share Posted July 31, 2006 I have updated the code as per below. I created a msg box that dumps the $msg1 and $msg2 values. I noticed that $msg1 is the command without quotes. E.g., {ALTDOWN}m{ALTUP} When I run this, half the time the {ALTDOWN}m{ALTUP} command works, and the other times it doesn't. I added the blockinput which helped a bit I think. Damn its frustrating... computers are supposed to be binary... either work or fail in this case, these different results are confusing the hell outta me expandcollapse popup; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.0 ; Author: A.N.Other <dodger@touch-buddy.com> ; ; Script Function: ; Send console messages to Lockon game ; ; --- Opt("WinWaitDelay",100) Opt("WinTitleMatchMode",4) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) $msg2 = "" If $CmdLine[0] = 0 Then MsgBox(0, "Usage", "lockonmsg.exe /t (team) or /a (all) message") Exit ElseIf $CmdLine[1] = "/?" Then MsgBox(0, "Usage", "lockonmsg.exe /t (team) or /a (all) message") Exit ElseIf $CmdLine[1] = "/ver" Then MsgBox(0, "Version", "v0.94 by dodger@touch-buddy.com") Exit ElseIf $CmdLine[1] = "/a" Then $msg1 = "{CTRLDOWN}m{CTRLUP}" $msg2 = $CmdLine[2] ElseIf $CmdLine[1] = "/t" Then $msg1 = "{ALTDOWN}m{ALTUP}" $msg2 = $CmdLine[2] ElseIf $CmdLine[1] = "/stat" Then $msg1 = "{ALTDOWN}m{ALTUP}" ;$msg2 = "" _GetStat() ;$msg2 = ""& $stat & "" EndIf ;If $CmdLine[3] = "/debug" Then ;MsgBox(0, "Variables:", $msg1 & " " &$msg2) ;DEBUG ;Else _LockonSend($msg1,$msg2) ;EndIf _LockonSend($msg1,$msg2) Func _LockonSend($msg1,$msg2) _ActiveLockon() BlockInput(1) ; Send("{CTRLDOWN}m{CTRLUP}") Send($msg1) Sleep(500) Send($msg2, 1) Sleep(100) Send("{ENTER}") Send($msg1) BlockInput(0) EndFunc Func _GetStat() $LockonPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Ubisoft\Eagle Dynamics\Lock On", "Path") $ExportDir = "\temp\" $ExportFile = ($LockonPath & $ExportDir &"exporttest.log") $Lines = _FileCountLines($ExportFile) $Readline = $Lines - 1 $file = FileOpen($ExportFile, 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $msg2 = FileReadLine($file, $Readline) FileClose($file) return $msg2 EndFunc Func _ActiveLockon() If Not WinExists("LOCK ON","") Then MsgBox(0, "Error", "Lockon is not running") If Not WinActive("LOCK ON","") Then WinActivate("LOCK ON","") WinWaitActive("LOCK ON","") Sleep(2000) EndFunc Func _FileCountLines($sFilePath) Local $N = FileGetSize($sFilePath) - 1 If @error Or $N = -1 Then Return 0 Return StringLen(StringAddCR(FileRead($sFilePath, $N))) - $N + 1 EndFunc Link to comment Share on other sites More sharing options...
nfwu Posted July 31, 2006 Share Posted July 31, 2006 half the time the {ALTDOWN}m{ALTUP} command worksTry !m instead. How would I go about encapsulating $msg with quotes? e.g., something like $msg2 = "\""& $msg2 & "\""Like this: Double up on the quotes:$msg2 = """" & $msg2 & """" #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
dodger42 Posted July 31, 2006 Author Share Posted July 31, 2006 (edited) Try !m instead. Like this: Double up on the quotes:$msg2 = """" & $msg2 & """"oÝ÷ Ûú®¢×©ä²¦ÃEYB&i×r§ë³*.q©ìyæÞ¶Ëb(®K9Óþt¶.'¶ jg¢|kzË-3(¬"Ó2+p¢¹,z÷«ÊئzÊ笲+j{ky©eÉ·èã.²ÖÞ¶¡×¬¢g¡£"ØbB¢éÝjµêç"Ø(zÉbëaÍE»-®éð¢¹,¥êßyËeËdrÝ®éìzwl¶¦zËëÅÇ©µú+¶¥jËL¢½÷3tá·kºwhzÉ÷öÛÖ§ÊØbjz'+ay-h§Ê+²¶§ªÞ¡÷ÛºÒ7ö÷®'jYl¢»l¡÷b}÷«z{lzÛbºÚ"µÍ[ÙRY ÌÍÐÛY[VÌWHH ][ÝËØI][ÝÈ[IÌÍÛÙÌHH ][Ý×I][ÝÂIÌÍÛÙÌH ÌÍÐÛY[VÌB[ÙRY ÌÍÐÛY[VÌWHH ][ÝËÝ ][ÝÈ[IÌÍÛÙÌHH ][ÝÉÌÌÎÛI][ÝÂIÌÍÛÙÌH ÌÍÐÛY[VÌB[ÙRY ÌÍÐÛY[VÌWHH ][ÝËÜÝ] ][ÝÈ[IÌÍÛÙÌHH ][ÝÉÌÌÎÛI][ÝÂNÉÌÍÛÙÌH ][ÝÉ][ÝÂWÑÙ]Ý] BNÉÌÍÛÙÌH ][ÝÉ][ÝÉ][ÝÉ][ÝÈ [È ÌÍÛÙÌ [È ][ÝÉ][ÝÉ][ÝÉ][ÝÂ[YÒY ÌÍÐÛY[VÌ×HH ][ÝËÙXYÉ][ÝÈ[NÓÙÐÞ ][ÝÕXXÎ][ÝË ÌÍÛÙÌH [È ][ÝÈ ][ÝÈ [ÉÌÍÛÙÌHÑPQÂÑ[ÙHÓØÚÛÛÙ[ ÌÍÛÙÌK ÌÍÛÙÌBBÑ[YBÓØÚÛÛÙ[ ÌÍÛÙÌK ÌÍÛÙÌBB[ÈÓØÚÛÛÙ[ ÌÍÛÙÌK ÌÍÛÙÌBBWÐXÝ]SØÚÛÛ BPØÚÒ[] JBÂTÙ[ ][ÝÞÐÕÕÓ[^ÐÕTI][ÝÊBBRY ÌÍÐÛY[VÌWHH ][ÝËÝ ][ÝÈÜ ][ÝËÜÝ] ][ÝÈ[TÙ[ ][ÝÉÌÌÎÛI][ÝÊBQ[ÙHTÙ[ ][Ý×I][ÝÊBQ[YNÔÙ[ ÌÍÛÙÌJBTÛY L BTÙ[ ÌÍÛÙÌJBTÛY BTÙ[ ][ÝÞÑSTI][ÝÊBTÛY BRY ÌÍÐÛY[VÌWHH ][ÝËÝ ][ÝÈÜ ][ÝËÜÝ] ][ÝÈ[TÙ[ ][ÝÉÌÌÎÛI][ÝÊBQ[ÙHTÙ[ ][Ý×I][ÝÊBQ[YNÔÙ[ ÌÍÛÙÌJBPØÚÒ[] B[[ Edited July 31, 2006 by dodger42 Link to comment Share on other sites More sharing options...
dodger42 Posted July 31, 2006 Author Share Posted July 31, 2006 Looks like the fix is this: Opt('SendKeyDownDelay', 50) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now