OK, now it's working!!

I had to write my patch like this:
Code:
local fn = '/mnt/ext1/applications/koreader/frontend/device/input.lua'
local fp = io.open( fn, "r" )
local str = fp:read( "*all" )
str = string.gsub( str, "%[framebuffer.DEVICE_ROTATED_UPRIGHT%] = %{%}", "%[framebuffer.DEVICE_ROTATED_UPRIGHT%] = %{ LPgBack = \"LPgFwd\", RPgBack = \"RPgFwd\" %}" )
fp:close()
fp = io.open( fn, "w+" )
fp:write( str )
fp:close()
So the brackets need the percentage sign in front of them. Cool!