Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Version 1.2
- using System;
- using System.Diagnostics;
- using System.Threading;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- namespace osu_Tapspeed
- {
- class Program
- {
- private const int WH_KEYBOARD_LL = 13;
- private const int WM_KEYDOWN = 0x0100;
- private const int WH_MOUSE_LL = 14;
- private const int WM_LBUTTONDOWN = 0x0201;
- private const int WM_RBUTTONDOWN = 0x0204;
- private static LowLevelProc _procK = HookCallbackK;
- private static LowLevelProc _procM = HookCallbackM;
- private static IntPtr _hookIDK = IntPtr.Zero;
- private static IntPtr _hookIDM = IntPtr.Zero;
- private static Stopwatch stopwatch = new Stopwatch();
- private static ConsoleKeyInfo hk1;
- private static ConsoleKeyInfo hk2;
- private static int taps;
- private static int taps_count;
- private static bool start;
- private static bool first = true;
- private static bool setkeys;
- #region Imports
- public delegate IntPtr LowLevelProc(int nCode, IntPtr wParam, IntPtr lParam);
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelProc lpfn, IntPtr hMod, uint dwThreadId);
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool UnhookWindowsHookEx(IntPtr hhk);
- [DllImport("kernel32.dll", SetLastError = true)]
- public static extern IntPtr GetModuleHandle(string lpModuleName);
- #endregion
- private static IntPtr HookCallbackK(int nCode, IntPtr wParam, IntPtr lParam)
- {
- try
- {
- if (nCode >= 0)
- {
- if ((int) wParam == WM_KEYDOWN)
- {
- if (start)
- {
- int vkCode = Marshal.ReadInt32(lParam);
- //Debug.WriteLine("vkCode: " + vkCode);
- if (vkCode == (int) hk1.Key || vkCode == (int) hk2.Key)
- {
- if (first)
- {
- stopwatch.Start();
- first = false;
- }
- if (taps_count == 0)
- {
- stopwatch.Stop();
- start = false;
- SendKeys.Send("{F15}");
- return CallNextHookEx(_hookIDM, nCode, wParam, lParam);
- }
- //Debug.WriteLine("KeyChar: " + vkCode);
- taps_count--;
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- //Debug.WriteLine("Error in HookCallbackK(): " + ex.Message);
- }
- return CallNextHookEx(_hookIDK, nCode, wParam, lParam);
- }
- private static IntPtr HookCallbackM(int nCode, IntPtr wParam, IntPtr lParam)
- {
- try
- {
- if (nCode >= 0)
- {
- if ((int)wParam == WM_LBUTTONDOWN || (int)wParam == WM_RBUTTONDOWN)
- {
- if (start)
- {
- if (hk1.Key == ConsoleKey.F13 && (int)wParam == WM_LBUTTONDOWN || hk1.Key == ConsoleKey.F14 && (int)wParam == WM_RBUTTONDOWN || hk2.Key == ConsoleKey.F13 && (int)wParam == WM_LBUTTONDOWN || hk2.Key == ConsoleKey.F14 && (int)wParam == WM_RBUTTONDOWN)
- {
- if (first)
- {
- stopwatch.Start();
- first = false;
- }
- if (taps_count == 0)
- {
- stopwatch.Stop();
- start = false;
- SendKeys.Send("{F15}");
- return CallNextHookEx(_hookIDM, nCode, wParam, lParam);
- }
- taps_count--;
- }
- }
- else
- {
- if (setkeys)
- {
- if ((int) wParam == WM_LBUTTONDOWN)
- SendKeys.Send("{F13}");
- else
- SendKeys.Send("{F14}");
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- //Debug.WriteLine("Error in HookCallbackM(): " + ex.Message);
- }
- return CallNextHookEx(_hookIDM, nCode, wParam, lParam);
- }
- static void Main(string[] args)
- {
- _hookIDK = SetWindowsHookEx(WH_KEYBOARD_LL, _procK, GetModuleHandle("user32"), 0);
- _hookIDM = SetWindowsHookEx(WH_MOUSE_LL, _procM, GetModuleHandle("user32"), 0);
- new Thread(Prog).Start();
- Application.Run();
- }
- private static void Prog()
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(@" ,--, _,.---._ ,-,--. ,--, ");
- Console.WriteLine(@" /-\==\,-.' , - `. ,-.'- _\ .--.-. .-.-. /-\==\ ");
- Console.WriteLine(@" / '/==/==/_, , - \/==/_ ,_.'/==/ -|/=/ | / '/==/ ");
- Console.WriteLine(@" / /==/==| .=. \==\ \ |==| ,||=| -| / /==/ ");
- Console.WriteLine(@" / -/==/|==|_ : ;=: - |\==\ -\ |==|- | =/ | / -/==/ ");
- Console.WriteLine(@" / `/==/ |==| , '=' |_\==\ ,\ |==|, \/ - | / `/==/ ");
- Console.WriteLine(@" / -/==/ \==\ - ,_ //==/\/ _ ||==|- , // -/==/ ");
- Console.WriteLine(@"/ `/==/ '.='. - .' \==\ - , //==/ , _ .'/ `/==/ ");
- Console.WriteLine(@"`--`-` `--`--'' `--`---' `--`..---' `--`-` ");
- Console.WriteLine(" [ osu!Tapspeed-meter for /osu/ ]");
- Console.WriteLine(" - by DaRealSlimOni -");
- Console.WriteLine("");
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("[~]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(" Tapkey1: ");
- setkeys = true;
- hk1 = Console.ReadKey(true);
- if (hk1.Key == ConsoleKey.F13)
- Console.WriteLine("LeftMouseButton");
- else if (hk1.Key == ConsoleKey.F14)
- Console.WriteLine("RightMouseButton");
- else
- Console.WriteLine(hk1.Key.ToString());
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("[~]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(" Tapkey2: ");
- hk2 = Console.ReadKey(true);
- if (hk2.Key == ConsoleKey.F13)
- Console.WriteLine("LeftMouseButton");
- else if (hk2.Key == ConsoleKey.F14)
- Console.WriteLine("RightMouseButton");
- else
- Console.WriteLine(hk2.Key.ToString());
- setkeys = false;
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("[~]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(" Taps: ");
- string line = Console.ReadLine();
- while (!Int32.TryParse(line, out taps))
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("ERROR! VALUE NOT VALID!");
- Console.Write("[~]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(" Taps: ");
- line = Console.ReadLine();
- }
- if (taps < 10)
- {
- taps = 10;
- Console.SetCursorPosition(0, Console.CursorTop - 1);
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("[~]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(" Taps: 10 ");
- }
- TapMeter();
- }
- private static void TapMeter()
- {
- taps_count = taps - 1;
- Console.WriteLine("");
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("[~]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(" Now start hitting keys! ");
- stopwatch.Reset();
- first = true;
- start = true;
- ConsoleKeyInfo key = Console.ReadKey(true);
- while (key.Key != ConsoleKey.F15)
- {
- key = Console.ReadKey(true);
- }
- Cont();
- }
- private static void Cont()
- {
- double t_ms = stopwatch.ElapsedMilliseconds;
- double t_sec = t_ms / 1000;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(" [+]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(" Time: " + t_sec + "sec");
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(" [+]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(" TapsPerMinute: " + (int)((taps / t_sec) * 60));
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(" [+]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(" maximal osu stream speed (1/4): " + (int)(((taps / t_sec) * 60) / 4) + "bpm");
- Console.WriteLine("");
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("[~]");
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write("Retry? (y/n) ");
- ConsoleKeyInfo key = Console.ReadKey(true);
- while (key.KeyChar != 'y' && key.KeyChar != 'n')
- {
- key = Console.ReadKey(true);
- }
- if (key.KeyChar == 'y')
- TapMeter();
- else
- {
- UnhookWindowsHookEx(_hookIDK);
- UnhookWindowsHookEx(_hookIDM);
- Application.Exit();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement