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.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace SlackyAsi
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- public string getSong()
- {
- try
- {
- Process processes = Process.GetProcessesByName("spotify").FirstOrDefault();
- if (processes.MainWindowTitle.Length > 10) // Halb lahendus
- {
- var raw = processes.MainWindowTitle;
- var song = raw.Substring(10, raw.Length - 10);
- return "Now Playing: " + song;
- }
- return "N/A";
- } catch {
- return "Spotify not running.";
- }
- }
- protected override void WndProc(ref Message m)
- {
- base.WndProc(ref m);
- if (m.Msg == 0x0312)
- {
- switch (((int)m.WParam))
- {
- case 13370:
- {
- MessageBox.Show(getSong());
- break;
- }
- }
- }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- RegisterHotKey(this.Handle, 13370, 0x0002, 120);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- MessageBox.Show(getSong());
- }
- [DllImport("user32.dll")]
- private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
- [DllImport("user32.dll")]
- private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement