I'm doing a project. I'm not going to details but I will simplify my idea. I'm using Morse Code ( dot and dash) and I have 2 methods: convert_MorseToChar()
and Convert_MorseTonum()
. In the convert_MorseToChar()
method there is a switch to compare the input from a user which will be Morse codes and mapping it to characters:
private String convert_MorseToChar(ref string Ch)
{
switch (Ch)
{
Case ".-":
MorsetoChar = "a"
break;
Case "-...":
MorsetoChar = "b"
break;
Case "-.-.":
MorsetoChar = "c"
break;
Case "-..":
MorsetoChar = "d"
break;
Case ".":
MorsetoChar = "e"
break;
}
}
and the other method Convert_MorseToNum(), ues the SAME combinations of Morse codes but mapping them to numbers:
private String Convert_MorseToNum(ref string Ch)
{
switch (Ch)
{
Case ".-":
MorsetoChar = "1"
break;
Case "-...":
MorsetoChar = "2"
break;
Case "-.-.":
MorsetoChar = "3"
break;
Case "-..":
MorsetoChar = "4"
break;
Case ".":
MorsetoChar = "5"
break;
}
}
Now the senario is: there are 2 Textbox, one the user will write Morse codes in it and the other is for the output. The user will write dot .
and dash -
from the keyboard and press Enter then the program will go to ONE of the 2 methods to convert the Morse codes. Now what tells the program where to go to convert?
my question is: I want to create mode key to switch between 2 modes: MorseToChar and MorseToNum. I want the down arrow key to act like a mode. When a user presses the down arrow then it the program will be in MorseToChar mode, whenever the user input the program directly use the method convert_MorseToChar
to convert to characters. When the user press the down arrow again, the program will switch to MorseToNum mode here when ever the user input as morsecode, the program will directly use the method Convert_MorseToNum()
to convert to numbers. How can I do that?
Please excuse my English, English is not my native language :)