The main obstacle to coherent control of two-level quantum systems is their coupling to an uncontrolled environment. For electron spins in III-V quantum dots, the random environment is mostly given by the nuclear spins in the quantum dot host material; they collectively act on the electron spin through the hyperfine interaction, much like a random magnetic field. Here we show that the same hyperfine interaction can be harnessed such that partial control of the normally uncontrolled environment becomes possible. In particular, we observe that the electron spin resonance frequency remains locked to the frequency of an applied microwave magnetic field, even when the external magnetic field or the excitation frequency are changed. The nuclear field thereby adjusts itself such that the electron spin resonance condition remains satisfied. General theoretical arguments indicate that this spin resonance locking is accompanied by a significant reduction of the randomness in the nuclear field.