Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Diagnostics;
  10. using System.Security.Cryptography;
  11. using System.Media;
  12.  
  13. namespace BruhSpeedrunTimer {
  14.     public partial class Form1 : Form {
  15.  
  16.         Stopwatch sw = new Stopwatch();
  17.  
  18.         [DllImport("User32.dll")]
  19.         public static extern short GetAsyncKeyState(Keys ArrowKeys);
  20.  
  21.         public Form1() {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void Form1_Load(object sender, EventArgs e) {
  26.             SetShowAdvanced(false);
  27.         }
  28.  
  29.         public string GetHash(string text) {
  30.             // [REDACTED]
  31.         }
  32.  
  33.         public string GetRawTimeStringNow() {
  34.             string paddedHr = DateTime.Now.Hour.ToString().PadRight(2, '0');
  35.             string paddedMin = DateTime.Now.Minute.ToString().PadRight(2, '0');
  36.             string paddedSec = DateTime.Now.Second.ToString().PadRight(2, '0');
  37.  
  38.             return paddedHr + ":" + paddedMin + ":" + paddedSec + "." + (DateTime.Now.Millisecond / 10).ToString().PadRight(2, '0');
  39.         }
  40.  
  41.         public void Log(string text) {
  42.             txtLog.AppendText(text);
  43.         }
  44.  
  45.         private void TimerTimeUpdater_Tick(object sender, EventArgs e) {
  46.             HandleKeyPresses();
  47.             toolStripStatusLabel1.Text = "Time: " + GetRawTimeStringNow();
  48.             string totalMinStr = ((int)sw.Elapsed.TotalMinutes).ToString().PadLeft(2, '0');
  49.             string totalSecStr = ((int)sw.Elapsed.Seconds).ToString().PadLeft(2, '0');
  50.             lblStopwatchMajor.Text = totalMinStr + ":" + totalSecStr;
  51.             lblStopwatchMinor.Text = sw.Elapsed.Milliseconds.ToString().PadLeft(3,'0');
  52.         }
  53.  
  54.         public void HandleKeyPresses() {
  55.             if (GetAsyncKeyState(Keys.F6) != 0 && button1.Enabled) {
  56.                 StartTimer();
  57.             }
  58.             if (GetAsyncKeyState(Keys.F7) != 0 && button2.Enabled) {
  59.                 PauseTimer();
  60.             }
  61.             if (GetAsyncKeyState(Keys.F8) != 0 && button3.Enabled) {
  62.                 ResetTimer();
  63.             }
  64.         }
  65.  
  66.         // Timer operations
  67.         public void StartTimer() {
  68.             Log("Started timer at " + GetRawTimeStringNow() + Environment.NewLine);
  69.             sw.Start();
  70.             txtHash.Text = GetHash(txtLog.Text);
  71.  
  72.             SystemSounds.Exclamation.Play();
  73.             SystemSounds.Exclamation.Play();
  74.  
  75.             button1.Enabled = false;
  76.             button2.Enabled = true;
  77.             button3.Enabled = true;
  78.         }
  79.  
  80.         public void PauseTimer() {      
  81.             Log("Stopped timer at " + GetRawTimeStringNow() + ", when it read " + lblStopwatchMajor.Text + "." + lblStopwatchMinor.Text + Environment.NewLine);
  82.             sw.Stop();
  83.             txtHash.Text = GetHash(txtLog.Text);
  84.  
  85.             SystemSounds.Exclamation.Play();
  86.             SystemSounds.Exclamation.Play();
  87.  
  88.             button1.Enabled = true;
  89.             button2.Enabled = false;
  90.             button3.Enabled = true;
  91.         }
  92.  
  93.         public void ResetTimer() {
  94.             Log("Reset timer at " + GetRawTimeStringNow() + ", when it read " + lblStopwatchMajor.Text + "." + lblStopwatchMinor.Text + Environment.NewLine);
  95.             sw.Reset();
  96.             txtHash.Text = GetHash(txtLog.Text);
  97.  
  98.             SystemSounds.Exclamation.Play();
  99.             SystemSounds.Exclamation.Play();
  100.  
  101.             button1.Enabled = true;
  102.             button2.Enabled = false;
  103.             button3.Enabled = false;
  104.         }
  105.  
  106.         private void Button1_Click(object sender, EventArgs e) {
  107.             StartTimer();
  108.         }
  109.  
  110.         private void Button2_Click(object sender, EventArgs e) {
  111.             PauseTimer();
  112.         }
  113.  
  114.         private void Button3_Click(object sender, EventArgs e) {
  115.             ResetTimer();
  116.         }
  117.  
  118.         private void BtnGetHash_Click(object sender, EventArgs e) {
  119.             txtOwnHash.Text = GetHash(txtOwn.Text);
  120.         }
  121.  
  122.         private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
  123.             SetShowAdvanced(!groupAdvanced.Visible);
  124.         }
  125.  
  126.         public void SetShowAdvanced(bool show) {
  127.             foreach (Control c in groupAdvanced.Controls) {
  128.                 c.Visible = show;
  129.             }
  130.             groupAdvanced.Visible = show;
  131.             if (show) {
  132.                 this.Size = new Size(this.Width, 550);
  133.             } else {
  134.                 this.Size = new Size(this.Width, 250);
  135.             }
  136.         }
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement