Re: iPhone 3gs
Are you saying that even when it is left untouched, the phone will not go into "sleep" mode on its own?
As far as a work around, I don't think you have many options here for replacing the function of the power/sleep button...but the button itself, given the age of the device, is probably needing to be replaced. Thankfully it's a very inexpensive part online (few bucks at most) and can be sourced on pretty much any phone repair website or, the easiest place, eBay.
There are probably a thousand DIY videos and write ups explaining how to do the replacement in detail...so you'd just have to search for those.