Kerala to Hampi or vice versa essentially involves multiple connections.
There are no direct connections from any of the major towns in Kerala to Hospet, which is the nearest railway station for Hampi.
By far train is the best possible option to travel to Hampi from Kerala. Though Hospet is the nearest railway station for Hampi, there are no direct trains (not yet at the time of writing this!) from Kerala that travel via Hospet.
But you have two broad choices. Travel to Goa and then travel to Hospet (and Hampi). Or travel to Guntakal Jn and then look for a connection to Hospet.
Of the two there are some half a dozen trains connect Kerala with Goa along the Konkan coast.
To Guntakal there are only two trains (the Mumbai Express Train No:16332; and the daily Kanyakumari Mumbai Jayanti Express Train No:16382 ).
From Goa to Hampi opt for a train connection to Hospet ( Howrah Express , Train No:18048 ) or even there are overnight buses from Goa to Hospet.
While this may not be the shortest, you may also consider a third train option, that is via Bangalore. You can catch that overnight Hampi Express (Train number 16592) from Bangalore to Hospet.
By there way there is a 12 hour or so bus (Rajahamsa service by KSRTC ) connection from Mangalore to Hopset. If you are traveling from the northern part of Kerala, explore the feasibility of this option too.
See also other travel options to reach Hampi.
Hyderabad to Hampi by Train
The most convenient train is the Hyderabad-Kolhapur Express (Train No:11303) or the Hyderabad - Vasco/Hubli Express (Train No:17603). On Thursdays you have one more train for Hampi, the Goa bound Hyderabad Vasco Da Gama express (Train No. 17021).
Bangalore to Hampi By Road
This is for the folks from Bangalore, still chewing over the idea if to take car or bike all the way to Hampi !