How to gather timing information of keystrokes using C#? [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to build a simple C# Windows Form Application that gathers user's keystrokes data.
Basically, the user needs to type in a word with length 10. I want to record each key's holding time, keydown to keydown time and keyup and keydown for adjacent keystrokes (so there are 10 + 9 + 9 = 28 measurements).
Could anyone tell me how to capture this information using text box events?
Thanks in advance

You can handle KeyUp and KeyDown events on your TextBox. You can get current timestamp using DateTime.Now.
Store your last KeyUp and KeyDown events time and add measurements like this:
private DateTime? keyUpTime = null;
private DateTime? keyDownTime = null;
private List<double> keyDownKeyUpMeasurements = new List<double>();
private List<double> keyDownKeyDownMeasurements = new List<double>();
private List<double> keyUpKeyDownMeasurements = new List<double>();
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
DateTime prevKeyDownTime = keyDownTime;
keyDownTime = DateTime.Now;
if (prevKeyDownTime != null)
{
keyDownKeyDownMeasurements
.Add(keyDownTime.Subtract(prevKeyDownTime).TotalMilliseconds);
}
if (keyUpTime != null)
{
keyUpKeyDownMeasurements
.Add(keyDownTime.Subtract(keyUpTime).TotalMilliseconds);
}
}
private void textBox_KeyUp(object sender, KeyEventArgs e)
{
keyUpTime = DateTime.Now;
keyDownKeyUpMeasurements
.Add(keyUpTime.Subtract(keyDownTime).TotalMilliseconds);
}

Related

Calculate average when checkbox are checked C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Good morning everyone!
So, I have 8 textboxes and under those are checkboxes. To those textboxes I'am always receiving data from a serialport and I need to do an average from those values. But I only want to do the average from the textboxes from which I checked the checkbox under them.
How can I add those values to the average formula when selected by checking the checkbox?
If anyone could help, I would really apreciate.
Thanks,
Jonathan
I think you should write something like this :
bool[] CheckBoxList { get; set; } = new bool[8];
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBoxList[0] = checkBox1.Checked;
CalcAverage();
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
CheckBoxList[1] = checkBox2.Checked;
CalcAverage();
}
in CalcAverage method , Textboxes with a true value in the list are computed.

C#: How can I make textarea that accepts only some specific words? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How can I make a TextArea that accepts only the words I have already set
with C# on Visual studio.
I'm a beginner in programming.
update:
what (-3) about?
like I said I'm a beginner, trying to build android game with c#.
until now just do some mistakes.
this website little complex to handle with but I will get used to it :) and my english poor
thank you all.
Use TextBox and add TextChanged event on your tool
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "^[a-zA-Z]"))
{
MessageBox.Show("This textbox accepts only alphabetical characters");
textBox1.Text.Remove(textBox1.Text.Length - 1);
}
}
More Info
textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged);
private void textBox1_TextChanged(object sender, EventArgs e)
{
Regex regex = new Regex(#"[^0-9^+^\-^\/^\*^\(^\)]");
MatchCollection matches = regex.Matches(textBox1.Text);
if (matches.Count > 0) {
//tell the user
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string yourWord = "mouse";
if (textBox1_Text.Text.Contains(yourWord))
{
textBox1_Text.Text.Replace(yourWord, "");
}
}

Visual effect on a mouse click in c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want that if i click on an image it gives a visual effect like whirl effect or glow effect or anything else on specific part around the point where i clicked with the mouse. for example if anyone has used the picture password of UC browser of windows phone exactly the same i want.
I have not tried anything because i have no knowledge of animation and graphics hence i haven't tried anything.
public void start()
{
messagebox.show("i haven't tried anything yet no knowledge of animation");
}
This code is nothing but i wrote it because i was not able to post the question.
In Winforms you could write code like this:
int AnimationCounter = 0;
Point AnimationCenter = Point.Empty;
Timer AnimationTimer = new Timer();
private void pictureBox1 _MouseClick(object sender, MouseEventArgs e)
{
AnimationCenter = e.Location;
AnimationTimer.Interval = 20;
AnimationTimer.Start();
}
void AnimationTimer_Tick(object sender, EventArgs e)
{
if (AnimationCounter > 15)
{
AnimationTimer.Stop();
AnimationCounter = 0;
pictureBox1.Invalidate();
}
else
{
AnimationCounter += 1;
pictureBox1.Invalidate();
}
}
private void pictureBox1 _Paint(object sender, PaintEventArgs e)
{
if (AnimationCounter > 0)
{
int ac = AnimationCounter / 2;
e.Graphics.DrawEllipse(Pens.Orange, AnimationCenter.X - ac,
AnimationCenter.Y - ac, ac * 2, ac * 2);
}
}
Don't forget to hook up the Paint and MouseClick event and also the AnimationTimer_Tick event.!
The result will draw a growing circle at the spot you click on which will disappear after ca. 10 * 20 ms..
Update: The first version suffered from repeatedly hooking up the Tick event. This one is better tested ;-)

Skype Tool CheckedListbox error [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm coding a Skype Tool.
I'm trying to get it to be black listed so they can spam people they won't from a checked list box but I set up everything right that I know of and I receive this on skype. system.windows.forms.checkedlistbox+checkeditemcollection it spams to that instead of the selected people I've chosen? Here's the code:
private void metroButton6_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(checkedListBox1.CheckedItems.ToString()) && !string.IsNullOrEmpty(metroTextBox5.Text))
{
timer3.Start();
}
}
private void timer3_Tick(object sender, EventArgs e)
{
skype.SendMessage(checkedListBox1.CheckedItems.ToString(), metroTextBox5.Text);
}
private void metroButton9_Click(object sender, EventArgs e)
{
timer3.Stop();
}
The SelectedItem of ComboBox is always a object which cannot be compared with a string. that's why you are getting such exception, so i suggest you to use:
metroComboBox1.SelectedItem.ToSting();
Hence your if will be like the following:
if (!string.IsNullOrEmpty(metroComboBox1.SelectedItem.ToString()) && !string.IsNullOrEmpty(metroTextBox1.Text))
{
// code here
}
and the sending message will be like this:
skype.SendMessage(metroComboBox1.SelectedItem.ToString, metroTextBox1.Text);
The reason for this error is metroComboBox1.SelectedItem is of type object. The method string.IsNullOrEmpty expects a string as parameter. So you can try this
if (!string.IsNullOrEmpty(metroComboBox1.SelectedItem as string) && ...
The as operator returns a string or null if metroComboBox1.SelectedItem is null or not a string.
But if SelectedItem is not a string you may rather use this:
if (!(metroComboBox1.SelectedItem == null ||
string.IsNullOrEmpty(metroComboBox1.SelectedItem.ToString())) && ...

How can i change the backcolor of picture box the number will taken from the textbox [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
private PictureBox[] picturebox = new PictureBox[64];
private void button2_Click(object sender, EventArgs e)
{
int i = int.Parse(textBox1.Text);
picturebox[i].BackColor = Color.Green;
}
when the button click i will take a number between 1 to 64 from user and i will change the backcolor of the picturebox which is want by user.
for ex:
int i=3;
pictureBox3.BackColor=color.green;
Try something like this:
int i = 3;
string PB= "pictureBox" + i;
PictureBox pb= this.Controls.Find(PB, true).FirstOrDefault() as PictureBox;
pb.BackColor = Color.Green;
Here you can find this example!

Categories

Resources