I need to do a button which has same functionality as PTT (Press to Talk).
So, you press and keep the button pressed - it does some function.
On release of the button, do something else.
while (button.pressed)
do something
on release
do something
ps. I found this code in a Forum, but it is not working. Nothing happens on pressing the button.
C#
isLooping = false;
//on mouse down
private void myControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
isLooping = true;
runLoop();
}
//on mouse up event
private void myControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
isLooping = false;
}
//This is the main loop you care about. Put this in your application
//This should go in its own thread
void runLoop() {
while (isLooping) {
//do stuff
}
}
VulpesRank #55 · 29.2K reputationPosted Aug 30, 2011, 12:23 AM EDT
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Aug 29, 2011, 5:18 AM EDT
I cant find out any MouseDown event handler in that code.... Change the first _MouseUp event handler to _MouseDown.
Asterix Obelix13 reputationPosted Aug 29, 2011, 5:20 AM EDT
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Aug 29, 2011, 5:23 AM EDT
Put break point on both events and the loop. check whether the isLooing is getting changed while press and release.
Asterix Obelix13 reputationPosted Aug 29, 2011, 5:34 AM EDT
__________________________________
void runLoop2() {
Skype.Attach(6, true);
SKYPE4COMLib.Command command1 = new SKYPE4COMLib.Command();
command1.Command = "SET MUTE ON";
command1.Blocking = false; command1.Id = 1000;
Skype.SendCommand(command1);
}
_______________________________
So, my idea is to mute the microphone on Pressed and on released unmute.
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Aug 29, 2011, 5:52 AM EDT
Asterix Obelix13 reputationPosted Aug 29, 2011, 5:57 AM EDT
But still, what should I add on the button itself (button click)?
Here is the code:
private void button1_Click_1(object sender, EventArgs e)
{
}
private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Skype.Attach(6, true);
SKYPE4COMLib.Command command1 = new SKYPE4COMLib.Command();
command1.Command = "SET MUTE OFF";
command1.Blocking = false;
command1.Id = 1000;
Skype.SendCommand(command1);
}
//on mouse up event
private void OnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
Skype.Attach(6, true);
SKYPE4COMLib.Command command1 = new SKYPE4COMLib.Command();
command1.Command = "SET MUTE ON";
command1.Blocking = false;
command1.Id = 1000;
Skype.SendCommand(command1);
}
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2011, 6:45 AM EDT
Asterix Obelix13 reputationPosted Aug 29, 2011, 6:55 AM EDT
I would like to ask another think.
How can I link a Hotkey to do this functionality of pressing the Button?
Thank you again!
VulpesRank #55 · 29.2K reputationPosted Aug 29, 2011, 7:55 AM EDT
Asterix Obelix13 reputationPosted Aug 29, 2011, 3:49 PM EDT
I tried what you suggested for the Hotkey, but it is not working.
Maybe I need also to link the methods (events) that you suggested as in the previous case?
I thought of putting the following link on form_load, but a detail is missing since it is not working:
this.button2.KeyDown += new KeyEventHandler(Form1_KeyDown);
this.button2.KeyUp += new KeyEventHandler(Form1_KeyUp);
Sam HobbsRank #107 · 20.5K reputationPosted Aug 29, 2011, 5:01 PM EDT
One of the many reasons for making a new thread is that the question about a hotkey is very unclear to me. I am very confused about what that actually means, but I won't even try to get clarification in this thread.
Asterix Obelix13 reputationPosted Aug 30, 2011, 1:40 AM EDT
Ganeshan R49 reputationPosted Aug 4, 2017, 4:11 AM EDT