Created
September 22, 2015 01:56
-
-
Save iz4blue/0669177d870552faee7d to your computer and use it in GitHub Desktop.
RaspberryPi touch screen get pos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File Edit Options Buffers Tools Python Help | |
# -*- coding:utf-8 -*- | |
import pygame | |
import sys | |
import os.path | |
BLACK = ( 0, 0, 0) | |
WHITE = (255, 255, 255) | |
GRAY = (126, 126, 126) | |
SCREEN_WIDTH = 1280 | |
SCREEN_HEIGHT = 1024 | |
def Main(): | |
pygame.init() | |
SCREEN_WIDTH = pygame.display.Info().current_w | |
SCREEN_HEIGHT = pygame.display.Info().current_h | |
print "%d x %d" % (SCREEN_WIDTH, SCREEN_HEIGHT) | |
size = (SCREEN_WIDTH, SCREEN_HEIGHT) | |
screen = pygame.display.set_mode(size) | |
pygame.mouse.set_visible(True) | |
font_big = pygame.font.Font(None, 50) | |
screen.fill(BLACK) | |
while True: | |
for event in pygame.event.get(): | |
if (event.type is pygame.MOUSEBUTTONDOWN) or (event.type is pygame.MOUSEBUTTONUP): | |
pos = pygame.mouse.get_pos() | |
print pos | |
text_pos = font_big.render(("%d x %d" % pos), True, WHITE) | |
pygame.draw.rect(screen, BLACK, [100, 100, 200, 200]) | |
screen.blit(text_pos, (100,100)) | |
pygame.display.flip() | |
if (event.type is pygame.KEYDOWN): | |
if event.key == K_ESCAPE: | |
sys.exit() | |
pygame.display.update() | |
Main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment