I am new to this website, well posting on here anyway. I've taught myself allot about programming and scripting, so I wanna thank everyone for posting.

This isn't my first program, but its the first useful thing I've done. It uses the 'w', 'a', 'd', 's' keys to move the mouse, similar to video games. Its the first step to a bigger project I'm working on in my spare time. Motion tracking to control the mouse. I know there are a lot of programs already for that. But it will teach me and its fun lol. I wanna get it running for someone I know. He is a quadriplegic "idk how to spell it" he can't move anything from the next down, thus not being able to use a computer. So when I'm done i will present it to the superintendent at my school to maybe getting it in all the schools with kids in similar situations.

Anyway now that I've talked your ear off here's the code.

# WADS mouse control
#writen by K.B. Carte "tech b"
#date 5/9/09

from ctypes import * #probably don't need all of it
import msvcrt  


user = windll.user32
a = 0
keyup = 'w'
keydwn = 's'
keylft = 'a'
keyrte = 'd'

x = 355      # roughly middle
y = 355

print """W = up, S = down, D = right, A = left
Press key and hold to move mouse
**Note: This console box must be up and selected

To exit click the "x" or "ctrl c"..."""

while a < 1:
 if msvcrt.kbhit():
   if keyup == msvcrt.getch():
      y = y - 10
      user.SetCursorPos(x,y)
   if keydwn == msvcrt.getch():
      y = y + 10
      user.SetCursorPos(x,y)
   if keylft == msvcrt.getch():
      x = x - 10
      user.SetCursorPos(x,y)
   if keyrte == msvcrt.getch():
      x = x + 10
      user.SetCursorPos(x,y)

Any criticizing is welcome, always up for deferent point of views =)

For the next part of my project is to get the motion tracking. Im using my webcam, possible an ir filter from a camera store, and videocapture lib. I've read some about it, but its not really sinking in. I could use some help, so any advice would be great. Just point me in the right direction because i want to 'self teach' as much as i can to help it really stick in my brain lol.
Thanks in advance!!!

Update. I use hooking now.
Requires pyWin32, pyhook.
The console is no longer required to by selected.

print "------WADS mouse control-----"
print "----written by K.B. Carte----"
print "--------date 2/18/10---------"
print ""
print ""
print ""

import pythoncom, pyHook, sys, win32api, time
from ctypes import *

user = windll.user32
speed = 10

######################################


PUL = POINTER(c_ulong)
class KeyBdInput(Structure):
    _fields_ = [("wVk", c_ushort),
             ("wScan", c_ushort),
             ("dwFlags", c_ulong),
             ("time", c_ulong),
             ("dwExtraInfo", PUL)]

class HardwareInput(Structure):
    _fields_ = [("uMsg", c_ulong),
             ("wParamL", c_short),
             ("wParamH", c_ushort)]

class MouseInput(Structure):
    _fields_ = [("dx", c_long),
             ("dy", c_long),
             ("mouseData", c_ulong),
             ("dwFlags", c_ulong),
             ("time",c_ulong),
             ("dwExtraInfo", PUL)]

class Input_I(Union):
    _fields_ = [("ki", KeyBdInput),
              ("mi", MouseInput),
              ("hi", HardwareInput)]

class Input(Structure):
    _fields_ = [("type", c_ulong),
             ("ii", Input_I)]

class POINT(Structure):
    _fields_ = [("x", c_ulong),
             ("y", c_ulong)]
# END SENDINPUT TYPE DECLARATIONS

FInputs = Input * 2
extra = c_ulong(0)

click = Input_I()
click.mi = MouseInput(0, 0, 0, 2, 0, pointer(extra))
release = Input_I()
release.mi = MouseInput(0, 0, 0, 4, 0, pointer(extra))


###################################################################
#Work cited: Case Nelson                                          # 
#http://mail.python.org/pipermail/python-list/2005-May/320761.html#
###################################################################

def clk():
  x = FInputs((0, click))
  user.SendInput(2, pointer(x), sizeof(x[0]))
def rel():
  a = FInputs((0, release))
  user.SendInput(2, pointer(a), sizeof(a[0]))

def OnKeyboardEvent(event):
    pos = win32api.GetCursorPos()
    if chr(event.Ascii) == 'w':
      user.SetCursorPos(pos[0],pos[1]-speed)
    if chr(event.Ascii) == 's':
      user.SetCursorPos(pos[0],pos[1]+speed)
    if chr(event.Ascii) == 'a':
      user.SetCursorPos(pos[0]-speed,pos[1])
    if chr(event.Ascii) == 'd':
      user.SetCursorPos(pos[0]+speed,pos[1])
    if chr(event.Ascii) == 'e':
      clk()
      rel()  
    return True

hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.