Skip to content

Commit

Permalink
Merge pull request #19 from 8128-33550336/develop
Browse files Browse the repository at this point in the history
デフォルトでできた
  • Loading branch information
8128-33550336 authored Jul 6, 2023
2 parents aa69f41 + 747dae2 commit f50030c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 41 deletions.
4 changes: 4 additions & 0 deletions README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ capture.keyEventEmitter.on("Control.C", () => {
});
```

## 注意

`process.stdin.on('data', listener)`をしているためstopしても止まりません.

# 参考

http://www.setgetweb.com/p/i5/rzaiwspecial.htm
Expand Down
21 changes: 3 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@8128-33550336/key-capture",
"version": "0.7.6",
"version": "0.8.0",
"description": "keyboard capture",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -24,8 +24,7 @@
"start": "node dist/main.js"
},
"dependencies": {
"@8128-33550336/typedeventemitter": "^1.1.2",
"node-termios": "^0.1.3"
"@8128-33550336/typedeventemitter": "^1.1.2"
},
"devDependencies": {
"@types/node": "^20.2.5",
Expand Down
22 changes: 2 additions & 20 deletions src/term.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
import { Termios, native } from "node-termios";
const { LFLAGS, IFLAGS } = native;

const captureSingleton = (() => {
const fd = 0;
const term = new Termios(fd);
let oldLFlags = term.c_lflag;
let oldIFlags = term.c_iflag;

let isCapturing = false;

const start = () => {
if (isCapturing) {
return;
}
isCapturing = true;
oldLFlags = term.c_lflag;
oldIFlags = term.c_iflag;
term.c_lflag &= ~LFLAGS.ECHO;
term.c_lflag &= ~LFLAGS.ICANON;
term.c_lflag &= ~LFLAGS.ISIG;
term.c_lflag &= ~LFLAGS.IEXTEN;
term.c_iflag &= ~IFLAGS.ICRNL;
term.c_iflag &= ~IFLAGS.IXON;
term.writeTo(fd);
process.stdin.setRawMode(true);
};
const stop = () => {
if (!isCapturing) {
return;
}
isCapturing = false;
term.c_lflag = oldLFlags;
term.c_iflag = oldIFlags;
term.writeTo(fd);
process.stdin.setRawMode(false);
};
const getIsCapturing = () => isCapturing;

Expand Down

0 comments on commit f50030c

Please sign in to comment.