Textbox to capture user's keyboard strokes

社会主义新天地 提交于 2019-12-11 14:17:55

问题


On one of the pages, there is a need for me to add a textbox in which the user types in text. It is important for us to capture what the user is thinking while he's typing in the text, so strokes such as backspace, keys should be captured. Once the user clicks on the submit button, the administrator should be able to 'play' the actions and review how the user progressed while he was typing in the text (similar to watching a video)

What would be the asp.net mvc or webforms way of doing this?


回答1:


Consider another non-control approach, or wrap this into your new control.

  • JavaScript capturing all KeyUp or KeyDown events. Difference between KeyPress, KeyDown, KeyUp.
  • logging each keystroke to an <input type='hidden' /> or <asp:Hidden>. Use the JavaScript KeyCode (here's another with some differences in JavaScript between browsers). There's a great sample at the bottom of that article. Append each keyCode to the value with your own separator. You'll end up with 34|73|91|13|
  • when the user is done, and you postback, find the value of the hidden field. You'll have a string of KeyCodes playing back the keystrokes that were captured in that textbox.



回答2:


I do not know if there is a custom control which already does this, in general I think you could implement your need in this way: save all key press with ClientSide OnKeyPress event, put all the key codes in a list, when user clicks submit pass this list to the server side code then you can simply re-apply all those changes in the same order, this is the video you wanted to play :)



来源:https://stackoverflow.com/questions/5135492/textbox-to-capture-users-keyboard-strokes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!