andybiochem Posted June 27, 2009 Share Posted June 27, 2009 (edited) Hi,I did a quick search to see if anyone has done this already, and whilst there are a few Morse code translators, there don't seem to be any actual Morse code generators.The idea behind this is that you tap the Morse code out using your space bar.The program then translates what you are tapping into normal text on the fly.I've tried to keep to the conventions set out in this wiki article:http://en.wikipedia.org/wiki/Morse_codei.e.:a dash is equal in length to three dotsspaces between letters of the same word = length of three dotsspaces between words = length of 7 dotsA dot length of 150ms works ok for me, but change it if necessary.Ideas / critisism welcome!!!expandcollapse popup#include <Misc.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) HotKeySet("{SPACE}", "_Null") ;****************************************** ; Vars ;****************************************** Global $bFirst = True;prevents leading / Global $nTD = "";dot/dah timer Global $nTLW = "";timer LW (looks for letter/word spaces) Global $iSn = 150;sensitivity of dot/dahs (i.e. length of 1 dot) Global $sSt = "";loading string Global $sString = "" Global $dll = DllOpen("user32.dll") ;----- Cipher ----- Global $aCipher[91] $aCipher[39] = ".----.";' $aCipher[44] = "--..--";, $aCipher[45] = "-....-";- $aCipher[46] = ".-.-.-";. $aCipher[48] = "-----";0 $aCipher[49] = ".----";1 $aCipher[50] = "..---";2 $aCipher[51] = "...--";3 $aCipher[52] = "....-";4 $aCipher[53] = ".....";5 $aCipher[54] = "-....";6 $aCipher[55] = "--...";7 $aCipher[56] = "---..";8 $aCipher[57] = "----.";9 $aCipher[58] = "---...";; $aCipher[63] = "..--..";? $aCipher[65] = ".-";a $aCipher[66] = "-...";b $aCipher[67] = "-.-.";c $aCipher[68] = "-..";d $aCipher[69] = ".";e $aCipher[70] = "..-.";f $aCipher[71] = "--.";g $aCipher[72] = "....";h $aCipher[73] = "..";i $aCipher[74] = ".---";j $aCipher[75] = "-.-";k $aCipher[76] = ".-..";l $aCipher[77] = "--";m $aCipher[78] = "-.";n $aCipher[79] = "---";o $aCipher[80] = ".--.";p $aCipher[81] = "--.-";q $aCipher[82] = ".-.";r $aCipher[83] = "...";s $aCipher[84] = "-";t $aCipher[85] = "..-";u $aCipher[86] = "...-";v $aCipher[87] = ".--";w $aCipher[88] = "-..-";x $aCipher[89] = "-.--";y $aCipher[90] = "--..";z ;****************************************** ; GUI ;****************************************** GUICreate("", 405, 660) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") ;----- Edits / Labels ----- $Label1 = GUICtrlCreateLabel("Morse Code Translator", 24, 8, 353, 41) GUICtrlSetFont(-1, 24, 800) $Label2 = GUICtrlCreateLabel("Tap the SPACEBAR to generate the morse code!!", 80, 56, 240, 17) $iShunt = 70 GUICtrlCreateLabel("MORSE CODE", 8, 25 + $iShunt, 385, 15) GUICtrlSetFont(-1, 10, 800) $Input1 = GUICtrlCreateInput("", 8, 40 + $iShunt, 385, 200, $ES_MULTILINE + $ES_READONLY) GUICtrlSetFont(-1, 12, 400) GUICtrlCreateLabel("TRANSLATION", 8, 265 + $iShunt, 385, 15) GUICtrlSetFont(-1, 10, 800) $Input2 = GUICtrlCreateInput("", 8, 280 + $iShunt, 385, 200, $ES_MULTILINE) GUICtrlCreateButton("Clear", 8, 560, 385, 40) GUICtrlSetOnEvent(-1, "_Clear") GUICtrlSetFont(-1, 16, 800) $ButtonSensitivity = GUICtrlCreateButton("Sensitivity (Dot length) = 150 ms", 8, 610, 385, 40) GUICtrlSetOnEvent(-1, "_Sensitivity") GUICtrlSetFont(-1, 16, 400) GUISetState() ;#################################################### ; LOOP ;#################################################### While 1 Sleep(10) If _IsPressed("20", $dll) = 1 Then ;----- look for letter/word pause ----- If $bFirst = False Then Switch TimerDiff($nTLW) Case ($iSn * 3) To ($iSn * 7) $sSt &= " " Case ($iSn * 7) + 1 To ($iSn * 99999) $sSt &= "/" EndSwitch EndIf $bFirst = False ;----- prep dot/dah timer ----- $nTD = TimerInit() ;----- detect dah from loop ----- Do Until _IsPressed("20", $dll) = 0 ;----- select dot/dah ----- Switch TimerDiff($nTD) Case 0 To $iSn $sSt &= "." Case Else $sSt &= "-" EndSwitch ;----- update input box ----- GUICtrlSetData($Input1, $sSt) ;----- translate current code ----- _Translate() ;----- set timer ----- $nTLW = TimerInit() EndIf WEnd ;#################################################### ; END LOOP ;#################################################### Func _Null() ;****************************************** ; Used only to hook the spacebar from apps ;****************************************** EndFunc ;==>_Null Func _Translate() ;****************************************** ; Translate code ;****************************************** $aSt = StringSplit($sSt, "/") ;----- decipher all but last word ----- $sString = "" For $i = 1 To $aSt[0] - 1 $aaSt = StringSplit($aSt[$i], " ") For $j = 1 To $aaSt[0] $iIndex = _ArraySearch($aCipher, $aaSt[$j]) Switch $iIndex Case - 1 $sString &= "?" Case Else $sString &= Chr($iIndex) EndSwitch Next $sString &= " " Next ;----- decipher last word (allow rolling edit) ----- $sStringTemp = "" $aaStTemp = StringSplit($aSt[$aSt[0]], " ") For $i = 1 To $aaStTemp[0] $iIndex = _ArraySearch($aCipher, $aaStTemp[$i]) Switch $iIndex Case - 1 $sStringTemp &= "?" Case Else $sStringTemp &= Chr($iIndex) EndSwitch Next ;----- update screen ----- GUICtrlSetData($Input2, $sString & $sStringTemp) EndFunc ;==>_Translate Func _Clear() ;****************************************** ; Clear current text / code ;****************************************** GUICtrlSetData($Input1, "") GUICtrlSetData($Input2, "") $sString = "" $sSt = "" $bFirst = True EndFunc ;==>_Clear Func _Sensitivity() ;****************************************** ; Set new sensitivity ;****************************************** $iSn = InputBox("","Set new sensitivity (dot length) in ms...",$iSn) GUICtrlSetData($ButtonSensitivity,"Sensitivity (Dot length) = " & $iSn & " ms") EndFunc Func _Exit() ;****************************************** ; Clean up and exit ;****************************************** DllClose($dll) Exit EndFunc ;==>_Exit Edited June 27, 2009 by andybiochem mLipok 1 - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
Andreik Posted June 27, 2009 Share Posted June 27, 2009 I like it. Link to comment Share on other sites More sharing options...
AlmarM Posted June 27, 2009 Share Posted June 27, 2009 Thats good. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
logmein Posted June 27, 2009 Share Posted June 27, 2009 It's hard to understand! [font=arial, helvetica, sans-serif][s]Total USB Security 3.0 Beta[/s] | [s]Malware Kill[/s] | Malware Scanner | Screen Hider | Locker | Matrix Generator[s]AUTO-SYNC 1.0 | MD5 Hash Generator | URL Checker | Tube Take [/s]| Random Text[/font] 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