0

I'm attempting to do something like the following:

let text = (event.ctrlKey) ? '\u0003' : String.fromCharCode(event.charCode || event.keyCode);
this.sendNewValue(text);

At the moment, text is always going to equal '\u0003' (ctrl+c for reference), as long as the control key is being held down, no matter what other key is also being pressed.

Is there a way for me to get the ASCII value for control key + [any key], ie.

ctrl+r = [some ASCII string]

benhowdle89
  • 36,900
  • 69
  • 202
  • 331
  • are you looking for this..???? http://stackoverflow.com/questions/4604057/jquery-keypress-ctrlc-or-some-combo-like-that – Himesh Aadeshara Aug 25 '15 at 14:02
  • @HimeshAadeshara It's less important that I know when that combo has been pressed, but more so that I can obtain the ASCII value. – benhowdle89 Aug 25 '15 at 14:04
  • How do you define what is the correct ASCII value? What would be the appropriate value if Ctrl-J is pressed for instance? How about Ctrl-(tilde) or Ctrl-Esc? Perhaps a better question would be, what are you actually trying to achieve with this approach? – enhzflep Aug 25 '15 at 14:07
  • @enhzflep Well, I'm following the logic that if '\u0003' is equal ctrl + c, then there must be other set ASCII values for other key combos? – benhowdle89 Aug 25 '15 at 14:09
  • Should I read that response as `"I don't know, but some combinations work - so surely there are others that are okay too?"` Basically, there isn't any correlation that I'm aware of. If you bring up a console window and hit Ctrl-D, you'll see `^D` printed. If on the other hand, I do the same in Notepad++, it duplicates the line - Ctrl-D isn't short-hand for a particular character, it's just interpreted differently in different environments. Hitting Ctrl-D here in the browser adds a bookmark. So, again I wonder - what are you actually trying to achieve? – enhzflep Aug 25 '15 at 14:15
  • @enhzflep you read that correctly! I'm emulating a CLI in the browser, so if I press CTRL + C, I'd like it to act as it would in a CLI, ie. a `SIGINT `. Also, if I press CTRL + R, I'd like it to put the CLI into reverse-i-search mode, for example. I guess I may just have to find out the ASCII values for specific combos, and just cater for those. (The strings get sent over a websocket to a real command line and executed) – benhowdle89 Aug 25 '15 at 14:19
  • @benhowdle89 - Ahhh-hah! Now I gotcha, your question makes far more sense to me now and presents more options for solving it. I'd consider doing all of that kind of stuff on the other end by simply simulating input. I'm not familiar with the means to do it in a *nix environment, so can't advise there. I'd just transmit the actual keys (scan-codes) pressed along with the Ctrl/Alt/Shift state and then pump out the simulated pressing of the same keys on the other end, allowing the OS to interpret them and cause the appropriate action. Sorry I cant be of greater use.. :) – enhzflep Aug 25 '15 at 14:25
  • @enhzflep It's a-ok, it's a highly specific, convoluted and custom problem to solve, so I'm grateful for any pointers! – benhowdle89 Aug 25 '15 at 14:28

0 Answers0