Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- using System.Security.Cryptography;
- using System.Media;
- namespace BruhSpeedrunTimer {
- public partial class Form1 : Form {
- Stopwatch sw = new Stopwatch();
- [DllImport("User32.dll")]
- public static extern short GetAsyncKeyState(Keys ArrowKeys);
- public Form1() {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e) {
- SetShowAdvanced(false);
- }
- public string GetHash(string text) {
- // [REDACTED]
- }
- public string GetRawTimeStringNow() {
- string paddedHr = DateTime.Now.Hour.ToString().PadRight(2, '0');
- string paddedMin = DateTime.Now.Minute.ToString().PadRight(2, '0');
- string paddedSec = DateTime.Now.Second.ToString().PadRight(2, '0');
- return paddedHr + ":" + paddedMin + ":" + paddedSec + "." + (DateTime.Now.Millisecond / 10).ToString().PadRight(2, '0');
- }
- public void Log(string text) {
- txtLog.AppendText(text);
- }
- private void TimerTimeUpdater_Tick(object sender, EventArgs e) {
- HandleKeyPresses();
- toolStripStatusLabel1.Text = "Time: " + GetRawTimeStringNow();
- string totalMinStr = ((int)sw.Elapsed.TotalMinutes).ToString().PadLeft(2, '0');
- string totalSecStr = ((int)sw.Elapsed.Seconds).ToString().PadLeft(2, '0');
- lblStopwatchMajor.Text = totalMinStr + ":" + totalSecStr;
- lblStopwatchMinor.Text = sw.Elapsed.Milliseconds.ToString().PadLeft(3,'0');
- }
- public void HandleKeyPresses() {
- if (GetAsyncKeyState(Keys.F6) != 0 && button1.Enabled) {
- StartTimer();
- }
- if (GetAsyncKeyState(Keys.F7) != 0 && button2.Enabled) {
- PauseTimer();
- }
- if (GetAsyncKeyState(Keys.F8) != 0 && button3.Enabled) {
- ResetTimer();
- }
- }
- // Timer operations
- public void StartTimer() {
- Log("Started timer at " + GetRawTimeStringNow() + Environment.NewLine);
- sw.Start();
- txtHash.Text = GetHash(txtLog.Text);
- SystemSounds.Exclamation.Play();
- SystemSounds.Exclamation.Play();
- button1.Enabled = false;
- button2.Enabled = true;
- button3.Enabled = true;
- }
- public void PauseTimer() {
- Log("Stopped timer at " + GetRawTimeStringNow() + ", when it read " + lblStopwatchMajor.Text + "." + lblStopwatchMinor.Text + Environment.NewLine);
- sw.Stop();
- txtHash.Text = GetHash(txtLog.Text);
- SystemSounds.Exclamation.Play();
- SystemSounds.Exclamation.Play();
- button1.Enabled = true;
- button2.Enabled = false;
- button3.Enabled = true;
- }
- public void ResetTimer() {
- Log("Reset timer at " + GetRawTimeStringNow() + ", when it read " + lblStopwatchMajor.Text + "." + lblStopwatchMinor.Text + Environment.NewLine);
- sw.Reset();
- txtHash.Text = GetHash(txtLog.Text);
- SystemSounds.Exclamation.Play();
- SystemSounds.Exclamation.Play();
- button1.Enabled = true;
- button2.Enabled = false;
- button3.Enabled = false;
- }
- private void Button1_Click(object sender, EventArgs e) {
- StartTimer();
- }
- private void Button2_Click(object sender, EventArgs e) {
- PauseTimer();
- }
- private void Button3_Click(object sender, EventArgs e) {
- ResetTimer();
- }
- private void BtnGetHash_Click(object sender, EventArgs e) {
- txtOwnHash.Text = GetHash(txtOwn.Text);
- }
- private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
- SetShowAdvanced(!groupAdvanced.Visible);
- }
- public void SetShowAdvanced(bool show) {
- foreach (Control c in groupAdvanced.Controls) {
- c.Visible = show;
- }
- groupAdvanced.Visible = show;
- if (show) {
- this.Size = new Size(this.Width, 550);
- } else {
- this.Size = new Size(this.Width, 250);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement