does anyone know how i can execute code by key press in python 2.7? I'm thinking that maybe i should make an invisible window and on key-press it executes code which i can have under a function? does anyone know how i can achieve that?
I'm trying to make something that takes screenshots and i have this, but i want it to be under a key-press instead of every time you run the program.
import wx
import random
import getpass
from time import gmtime, strftime
Time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
User = getpass.getuser()
app= wx.App()
screen = wx.ScreenDC()
size = screen.GetSize()
bmp = wx.EmptyBitmap(size[0], size[1])
mem = wx.MemoryDC(bmp)
mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
del mem # Release bitmap
Time = Time.replace(':','-')
Name = Time + '.png'
Name = Name.replace(' ', '%20')
bmp.SaveFile(Name, wx.BITMAP_TYPE_PNG)
Is there anyway i can make this activate underkeypress?