Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

i dont see any way of actually typing key presses, like modifiers.

This project looks pretty interesting, maybe i'm missing something.




To expand on what andyk wrote in the sibling comment:

Programs running in a terminal don't get individual components of composite key presses such as ctrl+a, shift+b, so they don't see "a with ctrl modifier" or "b with shift modifier". The modifier keys are handled by terminal emulator before sending the key's ascii value to the program, modifying the regular ascii letters appropriately. So when "a" (ascii value 0x61) is pressed while holding shift, its ascii value is ... shifted (down) by a constant 0x20, making it ascii 0x41, which represents "A". Similar with ctrl key, which shifts down the ascii value by 0x60, turning "a" into 0x01. So to send "ctrl+d" you send input with a single byte of value 0x04 ("d" ascii 0x64 minus 0x60). ht uses PTY under the hood, and this is how you send keyboard input into to a program via a PTY. This is kinda low level though, and there's definitely a possibility of implementing a high level input method in ht, which would parse string such as "<ctrl+d>" and automatically turn it into 0x04 before sending it to the process.

In other words, the way input in ht works right now was the easiest, simplest way of implementing this to get it out the door.


Include in your input json the ascii control character that the keyboard combo would generate (e.g., \x03 for ctrl-c).

To send control-c to the terminal, for example, you'd send the following JSON message to ht:

  { "type": "input", "payload": "\x03" }




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: