If you search this forum, you'll find there are several solutions. I won't do the search for you but the solutions involve either CTI (there's even a device state server function in newer JTAPI releases), calling the ModeInfo page to get an XML representation of what's currently on screen, or looking at the statistics page.