  There are several strong K I lines found in the spectra of M dwarfs, among
them the doublet near 7700 AA and another doublet near 12 500 AA. We study
these optical and near-infrared doublets in a sample of 324 M dwarfs, observed
with CARMENES, the high-resolution optical and near-infrared spectrograph at
Calar Alto, and investigate how well the lines can be used as photospheric and
chromospheric diagnostics. Both doublets have a dominant photospheric component
in inactive stars and can be used as tracers of effective temperature and
gravity. For variability studies using the optical doublet, we concentrate on
the red line component because this is less prone to artefacts from telluric
correction in individual spectra. The optical doublet lines are sensitive to
activity, especially for M dwarfs later than M5.0 V where the lines develop an
emission core. For earlier type M dwarfs, the red component of the optical
doublet lines is also correlated with H$\alpha$ activity. We usually find
positive correlation for stars with H$\alpha$ in emission, while early-type M
stars with H$\alpha$ in absorption show anti-correlation. During flares, the
optical doublet lines can exhibit strong fill-in or emission cores for our
latest spectral types. On the other hand, the near-infrared doublet lines very
rarely show correlation or anti-correlation to H$\alpha$ and do not change line
shape significantly even during the strongest observed flares. Nevertheless,
the near-infrared doublet lines show notable resolved Zeeman splitting for
about 20 active stars which allows to estimate the magnetic fields B.
