Converting from Blender to Game Engine

I have two questions

  1. The following code generates random poses of a hand and its fingers (ive only included the pinky and wrist here to save space)

import bpy
import random
import time
import string
import random
import os
from mathutils import * 
from math import * 

def rand_lim(lims):
    x = lims[0] + random.random() * (lims[1] - lims[0]);
    return x

hand = bpy.data.objects["Armature"];
scale = rand_lim( (0.8 , 1.0) );
hand.scale = ( scale, scale, scale );
    
hand.rotation_mode = 'ZXY'
rx = rand_lim((-45.0,45.0)); ry = rand_lim((-45.0,45.0));rz = rand_lim((-45.0,45.0));
hand.rotation_euler = ( rx/57.3, ry/57.3, rz/57.3 ); 
    
x = rand_lim((-0.5,0.5)); y = rand_lim((-0.5,0.5)); z = rand_lim((-0.5,0.3));
hand.location = ( x , y , z );
    
hand_pose = hand.pose;
    
for bone in hand_pose.bones:
    bone.rotation_mode = "XYZ";
    bone.rotation_euler = (0,0,0);
    
    # bone_name - which bone 
    # phi   - left right angle    
    # theta - forward backward angle
def set_rot( pose, bone_name, phi_lims, theta_lims ): 
    phi     = rand_lim(phi_lims);
    theta   = rand_lim(theta_lims);
    pose.bones[bone_name].rotation_euler = ( -phi/57.3, 0 , -theta/57.3 );

set_rot(hand_pose,  'wrist',         ( -10 , 10 ),  ( -30 , 30 ) );
set_rot(hand_pose,  'pinkybase',     ( -3 , 3 ),  ( -2 , 2 ) );
set_rot(hand_pose,  'pinkylower',    ( -5 , 5 ),  ( -3 , 90 ) );
set_rot(hand_pose,  'pinkymiddle',   ( 0 , 0 ),  ( 0 , 90 ) );
set_rot(hand_pose,  'pinkytop',      ( 0 , 0 ),  ( 0 , 90 ) );

How can I convert this to do the same in BGE?

How can I print out the depth and color buffer of the current BGE viewport?
How do I specifically access the viewport? Is bgl.glReadPixels enough and if so on what?

You will probably want to use the armature object API:
http://www.blender.org/documentation/blender_python_api_2_63_release/bge.types.html#bge.types.BL_ArmatureObject

Thanks, that is more or less what I need.

Regarding the second question:
How can I perform a screen capture of the current color AND depth images of the view visible?
If I use makeScreenShot and have two cameras then how do I define one camera to be active and the other not?

I figured out I can just apply a Custom Filter actuator that returns depth instead of color. If there is a better, more correct way Id love to hear!
Alternatively if there is a better way to get the depth image Id be happy to hear!