Hi everyone,
I need to build a morse code translator program using the keys on the keyboard.
I have already found out how to translate the morse code itself to text but I still have one major problem.
I need to find out how long I'm pressing a certain key to determined if this is a dash, a dot or a space (morse language). In order to do so I think I need to use the key_down function and the timer, but I don't really figured out how.
I also need to do this method a long duration of time (if I want to write a sentence) so the operation shouldn't run only once.
Can you help me or even give me some guidance?
Aleksandar IlioskiPosted Mar 11, 2009, 9:54 PM
try this! Hope it will help you...
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
timer1.Start();
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
string morseLeter=null;
timer1.Stop();
if (seconds <= 1)
{
morseLeter="dot";
}
if (seconds >= 2)
{
morseLeter= "dash";
}
MessageBox.Show("the key: "+e.KeyData.ToString() +" was press :" + seconds.ToString() + " seconds" + ", so it is " + morseLeter);
seconds = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
seconds ++;
}
KostaPosted Nov 4, 2009, 8:44 AM
Aleksandar IlioskiPosted Mar 24, 2009, 8:43 PM
alonPosted Mar 20, 2009, 10:48 AM
if it helps you to see how i've written the program with the KeyDown and the KeyUp function here it is: (the timers interval is 10)
private
void timer1_Tick(object sender, EventArgs e){
this.timing++;}
private void timer2_Tick(object sender, EventArgs e){
this.timing2++;}
private void Form1_KeyDown(object sender, KeyEventArgs e){
timer2.Stop();
if (this.timing2 >= 50 && this.timing2 <= 150){
this.morseLeter = " ";}
timer1.Start();
this.timing2 = 0; this.mst += this.morseLeter; this.morseLeter = null;}
private void Form1_KeyUp(object sender, KeyEventArgs e){
timer1.Stop();
timer2.Start();
if (this.timing > 0 && this.timing <= 15){
this.morseLeter = ".";}
if (this.timing > 15){
this.morseLeter = "-";}
this.timing = 0; this.mst += this.morseLeter; this.morseLeter = null;}
alonPosted Mar 20, 2009, 10:45 AM
Hi again,
After successfully building my Morse translating program i've built an electronic circuit with a buzzer and a microphone who record the buzzer morse signals. i've placed there also a LPT port with which i can get the signal data received by the microphone to my computer.
in order to read this data i've placed a dll file called "inpout32.dll" into my WINDOWS\system32\ dir, then i've put these lines in my program:
//Call Input function from DLL file
[
DllImport("inpout32.dll", EntryPoint = "Inp32")] public static extern int Input(int adress);and then when my microphone receives a buzz (similar to KeyDown) the Input(0x379) function returns 111 (an integer), and when it doesn't receive a buzz (similar to KeyUp) the Input(0x379) function returns 127 (an integer).
With that information in mind, how do i build the same morse code translating program using this Input function?
Aleksandar IlioskiPosted Mar 13, 2009, 11:33 AM
alonPosted Mar 13, 2009, 10:25 AM
Thank you very much! It helped me undrstanding what should I do.
If I have more problems I will ask here again.
alonPosted Mar 11, 2009, 5:27 PM
yes i'm using C#
Aleksandar IlioskiPosted Mar 11, 2009, 1:19 PM