[pygame] Capture tablet pressure?

233 views
Skip to first unread message

Eric Pavey

unread,
Oct 11, 2009, 6:21:20 PM10/11/09
to pygame...@seul.org
Been searching around, and haven't come up with anything:  Anyone know how to capture tablet pressure in Pygame?  Pygame recognizes my tablet (Wacom Bamboo) just fine as a mouse, buttonclicks etc, but no "pressure" based on those clicks.  Any advice?  Is it possible that SDL doesn't support tablets?

thanks

James Paige

unread,
Oct 11, 2009, 6:36:12 PM10/11/09
to pygame...@seul.org

No, I'm pretty sure SDL does not have any pressure support. Although I
think that pressure sensitivity and multitouch may be planned for SDL
1.3/2.0, (maybe somebody can correct me if I am mistaken on that)

I remember hearing a rumor that pygtk supports pressure sensitivity, but
making pygame and pygtk work together might prove to be more trouble
than it is worth.

Also, some quick googling turns up pymt, which might be helpful, but I
haven't tried it myself.

---
James

Jake b

unread,
Oct 11, 2009, 9:30:15 PM10/11/09
to pygame...@seul.org
maybe this? http://stackoverflow.com/questions/45500/wacom-tablet-python-interface

I'm definitely interested if you get python+wacom pressure working.

Maybe you can read events yourself ( but would make it platform specific )?


--
Jake

machi...@gmail.com

unread,
Oct 11, 2009, 9:45:06 PM10/11/09
to pygame...@seul.org
i think you could use cgkit. it includes a wintab wrapper if i remember correctly.

Eric Pavey

unread,
Oct 12, 2009, 1:00:03 PM10/12/09
to pygame...@seul.org
So I tried the cgkit\wintab route.  Had some success, but still can't get the dang pressure.  Below is the code I came up with if anyone wants to poke at it  When ran, it prints stuff like:
<Packet btns:1 x:10937 y:2140> 0 0
With the last two values representing pressure.  Well, it's a start ;)

# pressure.py
import os
import pygame
from cgkit import wintab

pygame.init()

hwnd = 1024
os.environ["SDL_WINDOWID"] = str(hwnd)

def main():
screen = pygame.display.set_mode((640, 480))
background = pygame.surface.Surface(screen.get_size())
background.fill(pygame.color.Color("Black"))
screen.blit(background, (0,0))

#--------------------------------------------
# Creates a "Context" object:
tablet = wintab.Context()
tablet.open(hwnd, True)

looping = True
while looping:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
# allow for exit:
looping = False

#--------------------------------------------
# Get a tuple of range of packets captured: (first, last)
packetExtents = tablet.queuePacketsEx()
if packetExtents[1] is not None:
# This is a sub-list of Packet objects:
packets = tablet.packetsGet(packetExtents[1])
# Get the last Packet object:
packet = packets[-1]
# Print packet info, and pressure data:
print packet, packet.normalpressure, packet.tangentpressure

pygame.display.flip()
pygame.quit()

if __name__ == "__main__":
main()


Eric Pavey

unread,
Oct 15, 2009, 12:56:24 AM10/15/09
to pygame...@seul.org
If anyone is interested, I got this working.  Posted on my blog\Pygame, with pointers to source download:
http://www.akeric.com/blog/?p=777
http://www.pygame.org/project-Tablet+Pressure-1302-2287.html

René Dudfield

unread,
Oct 15, 2009, 1:39:28 AM10/15/09
to pygame...@seul.org
sweet :)  nice work.
Reply all
Reply to author
Forward
0 new messages