Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return key press event key has ctrl=true #27

Open
mmitchellg5 opened this issue Mar 28, 2023 · 3 comments
Open

return key press event key has ctrl=true #27

mmitchellg5 opened this issue Mar 28, 2023 · 3 comments
Labels

Comments

@mmitchellg5
Copy link

mmitchellg5 commented Mar 28, 2023

Describe the problem

return key press event key has ctrl=true
#
when only pressing return, and not ctrl

Steps to reproduce the problem

  reader.on(:keypress) do |event|
    puts event.key
  end

Actual behaviour

#<struct TTY::Reader::Key name=:return, ctrl=true, meta=false, shift=false>

Expected behaviour

#<struct TTY::Reader::Key name=:return, ctrl=false, meta=false, shift=false>

Describe your environment

  • OS version: macos 13.2.1
  • Ruby version: 3.2.1
  • TTY::Reader version: tty-reader (0.9.0)
@mmitchellg5
Copy link
Author

[8] pry(TTY::Reader::KeyEvent)> TTY::Reader::Keys.ctrl_keys[c]
=> :ctrl_m
[9] pry(TTY::Reader::KeyEvent)> c
=> "\r"
[10] pry(TTY::Reader::KeyEvent)> TTY::Reader::Keys.ctrl_keys
=> {"\u0001"=>:ctrl_a,
 "\u0002"=>:ctrl_b,
 "\u0003"=>:ctrl_c,
 "\u0004"=>:ctrl_d,
 "\u0005"=>:ctrl_e,
 "\u0006"=>:ctrl_f,
 "\a"=>:ctrl_g,
 "\b"=>:ctrl_h,
 "\t"=>:ctrl_i,
 "\n"=>:ctrl_j,
 "\v"=>:ctrl_k,
 "\f"=>:ctrl_l,
 "\r"=>:ctrl_m,
 "\u000E"=>:ctrl_n,
 "\u000F"=>:ctrl_o,
 "\u0010"=>:ctrl_p,
 "\u0011"=>:ctrl_q,
 "\u0012"=>:ctrl_r,
 "\u0013"=>:ctrl_s,
 "\u0014"=>:ctrl_t,
 "\u0015"=>:ctrl_u,
 "\u0016"=>:ctrl_v,
 "\u0017"=>:ctrl_w,
 "\u0018"=>:ctrl_x,
 "\u0019"=>:ctrl_y,
 "\u001A"=>:ctrl_z,
 "\u0000"=>:ctrl_space,
 "\u001C"=>:ctrl_backslash,
 "\u001D"=>:ctrl_square_close,
 "\e[1;5A"=>:ctrl_up,
 "\e[1;5B"=>:ctrl_down,
 "\e[1;5C"=>:ctrl_right,
 "\e[1;5D"=>:ctrl_left}
[11] pry(TTY::Reader::KeyEvent)>

Maybe this is expected for reasons i dont know about? Is \r supposed to map to :ctrl_m ?

@mmitchellg5
Copy link
Author

mmitchellg5 commented Mar 28, 2023

i guess so.
https://stackoverflow.com/a/3936449
Screenshot 2023-03-27 at 10 59 18 PM

so what do i do then if i want to listen for ctrl+return or shift+return

@mmitchellg5
Copy link
Author

mmitchellg5 commented Mar 28, 2023

 $ showkey                           
Type any key to see the sequence it sends.
Terminate with your shell interrupt <CTL-C=ETX> or quit <FS> character.
<CTL-J=LF><CTL-J=LF><CTL-J=LF>
    #enter #ctrl+enter #shift+enter

does this mean my keyboard is sending CTL-J, or that is what my terminal is sending to the shell?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant