[Tutor] How to capture 'Ctrl+c' in Python

Luke Paireepinart rabidpoobear at gmail.com
Fri Nov 3 05:40:38 CET 2006


Chris Hengge wrote:
> I've got your code at home, and I know it picks up shift and ctrl 
> modified items, but it wont register print screen (among a few 
> others). I can post the code I have at home later if you want to 
> verify it. I've been given a few methods to try in my other thread I 
> just started on here which are more practical, but I'm still 
> interested in this.
Pygame can capture it just fine. 
import pygame
from pygame.locals import *
pygame.init()
scr = pygame.display.set_mode((640,480))
while 1:
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            print event
            if event.key == K_ESCAPE:
                pygame.quit()
                raise SystemExit

when you hit print screen you will see that the keycode is 311,
so just do a
if event.key == 311:
if you want to check if they hit print screen.
But this doesn't really help you probably because I don't think you're 
using Pygame.
Just thought i'd mention that.
>
> On 11/2/06, *Alan Gauld* <alan.gauld at btinternet.com 
> <mailto:alan.gauld at btinternet.com>> wrote:
>
>
>     "Chris Hengge" <pyro9219 at gmail.com <mailto:pyro9219 at gmail.com>> wrote
>     > Do you by chance know of a way to capture special keys like "Print
>     > Screen"?
>
>     Try the key capture code in my Event Driven topic.
>
>     So far as I know it works for all keys including the special ones.
>     It also points out that those keys have a two part code...
>
>     --
>     Alan Gauld
>     Author of the Learn to Program web site
>     http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>     _______________________________________________
>     Tutor maillist  -  Tutor at python.org <mailto:Tutor at python.org>
>     http://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   



More information about the Tutor mailing list