Ok, after found this topic and change a bit of code I made it to works. This is the result:
$(".btn").click(function() {
var tree = $("#tree").dynatree("getTree");
var selKeys = $.map(tree.getSelectedNodes(), function(node) {
return node.data.key;
})
$("#selcs").val(selKeys);
});
Hope can help others