What you want to do may not be easy; however, using the magic wand tool is. Just use scriptListener to record using the magic wand tool, then just exchange variables for all the values that you normally set like tolerance, and put in the points where you want the magic wand to sample.
function quickSel (x, y, tol){
var idsetd = charIDToTypeID( "setd" );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref1.putProperty( idChnl, idfsel );
desc2.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc3 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idHrzn, idPxl, x );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idVrtc, idPxl, y);
var idPnt = charIDToTypeID( "Pnt " );
desc2.putObject( idT, idPnt, desc3 );
var idTlrn = charIDToTypeID( "Tlrn" );
desc2.putInteger( idTlrn, tol);
var idAntA = charIDToTypeID( "AntA" );
desc2.putBoolean( idAntA, true );
var idCntg = charIDToTypeID( "Cntg" );
desc2.putBoolean( idCntg, true );
executeAction( idsetd, desc2, DialogModes.NO );
};