Here's a quote from the
DOTA2 Eurogamer series (which everyone should read):
"Dota 2 is fencing.
That's the skill, and the appeal. I finally see it. You're fighting back and forth down these lanes, looking for an opening in the other heroes' defense. The other guy's too close to your tower, or too far from his friend, his ultimate skill's on cooldown, his health is low. Fights in other games last seconds. Fights in Dota 2 are dramatic; entire minutes of feints and narrow escapes. Duels that can span forests, roads and rivers without coming to an end."
That's especially true when you're trying to farm with a melee hero. You'll only want to go in for last hits when it's safe, and figuring out what makes you safe is a large part of learning how to play DOTA. For now, make sure you have enough of your creeps such that if an enemy hero right clicks you they'll get chased back or attacked (creeps automatically target heroes when they right click other heroes). If you don't, stay back out of enemy range. Conversely, if you're a ranged hero, it's important to figure out how to hit an enemy once or twice and then back off so you don't take more than a couple of hits from creeps. If you see their creep wave only has one left and they're sticking around, poke at them, attack them, etc. If you're playing a melee that needs a lot of farm, it's also useful to have a support hero that can stun enemies or heal you if you're in danger. And remember that when they dart out at you, they're darting into range of your and your lane mate's abilities. That doesn't mean you should always attack back, but eventually you'll learn to see openings.
As for whether to prioritize last hitting or denying, that depends on what kind of hero you're playing. If you're a carry, you need a lot of farm. If you're support, you should probably give most of the last hits to your partner in lane (when applicable) and focus on last hitting. Ideally you want to do both (unless you're supporting a carry, then ideally you give them all of the last hits).