After the Nile Expedition of 1885 had reached its sad conclusion, Hamilton returned to India and became an aide-de-camp on the staff of Lord Roberts, who was then commanding the Madras army. The question of musketry training for Infantry was at that time much discussed, and Lord Roberts was determined to do something to improve the shooting of the British army. In his book 'Forty-one Years in India' he tells us how he and his staff formed themselves into a team and had many exciting rifle matches with the regiments in the Madras command. In all this Hamilton's skill with the rifle and the keen interest he had always shown for musketry--his first regimental appointment had been to be Musketry Instructor--stood him in good stead, and when Lord Roberts became Commander-in-Chief in India his aide-de-camp, who had meanwhile served in the Burmah campaign, was made Assistant Adjutant-General for Musketry.
In 1886 he married Jean, daughter of Sir John Muir, Baronet, of Deanston, Perthshire. He had now determined to persevere in the military profession, and devoted himself to it with great assiduity. His literary talents were turned to military subjects. He published a book on musketry in the army entitled 'The Fighting of the Future.' It was strong and well written. The introduction of the magazine rifle has modified many of his conclusions, but at the time the book attracted a great deal of attention. He found time, however, to write on other things, and there are still extant from his pen: 'A Jaunt in a Junk,' an account of a cruise which he made with his brother down the west coast of India; a volume of verses, 'The Ballad of Hadji and the Boar'; and one or two other writings. He preserved and extended his acquaintance with literary men, particularly with Andrew Lang, whom he powerfully impressed, and who inscribed a volume of poems to him in the following compulsive lines:
To you, who know the face of war, You, that for England wander far, You that have seen the Ghazis fly From English lads not sworn to die, You that have lain where, deadly chill, The mist crept o'er the Shameful Hill, You that have conquered, mile by mile, The currents of unfriendly Nile, And cheered the march, and eased the strain When Politics made valour vain, Ian, to you, from banks of Ken, We send our lays of Englishmen!