Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard history program
#1
Hi guys!

I've been making a keyboard history program called ClipboardHero in python which stores your last clipboard entries in a file. I have encountered two problems while making this program:
  • I need the Ctrl-C keys to activate the program even when the window is not in focus
  • I need it to activate not only with Ctrl-C but with right-click+Copy as well

I would grateful if anyone could help! Smile

The code:
from tkinter import *
from tkinter import messagebox
import winsound

subMenu = Tk()
subMenu.title("ClipboardHero")
subMenu.attributes("-topmost", True)
subMenu.overrideredirect(True)
subMenu.withdraw()

menuShown = False

clipboardSaves = open("clipboard.txt", "a")
clipboardSaves.close()

def copy():
    global menuShown
    clipboard = str(subMenu.clipboard_get())

    clipboardSaves = open("clipboard.txt", "a+")
    clipboardSaves.write("\n" + clipboard)
    clipboardSaves.close()

    messagebox.showinfo("ClipboardHero - Clipboard saved", "Your current clipboard has been saved!\n" + clipboard)
    menuShown = False
    subMenu.withdraw()

def hideMenu():
    subMenu.withdraw()
    menuSHown = False
    
def showMenu(event):
    global menuShown
    
    if menuShown == False:
        winsound.Beep(400, 300)
        winsound.Beep(600, 300)
        
        subMenu.deiconify()

        Label(subMenu, text = "Do you want to copy this text to ClipboardHero?").grid(row = 0, column = 0)

        yes = Button(subMenu, text = "Yes", width = 50, bg = "green", command = copy)
        yes.grid(row = 1, column = 0)

        no = Button(subMenu, text = "No", width = 50, bg = "red", command = hideMenu)
        no.grid(row = 2, column = 0)

        menuShown = True
        subMenu.mainloop()

subMenu.bind("<Control-c>", showMenu)
Reply


Messages In This Thread
Keyboard history program - by chesschaser - May-06-2020, 09:44 PM
RE: Keyboard history program - by Larz60+ - May-10-2020, 05:25 PM
RE: Keyboard history program - by chesschaser - May-12-2020, 10:24 AM
RE: Keyboard history program - by Larz60+ - May-12-2020, 06:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Build a DNS History Rudeus 2 732 Aug-11-2023, 09:52 PM
Last Post: Rudeus
  why is yfinance returning an ellipsis in the middle of ticket history db042190 3 1,113 Jun-12-2023, 06:03 PM
Last Post: db042190
  Coding a logger for firefox history kpiatrou 2 2,987 Dec-25-2018, 06:42 PM
Last Post: snippsat
  How to handle "History" in ptpython sylas 4 4,158 Oct-07-2018, 11:09 PM
Last Post: Larz60+
  How to differentiate displacement-time history muhsin 1 2,914 Feb-14-2018, 11:50 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020