NodeJS blessed no key events - node.js

I am new to using the blessed library and so far, I could not get key events to work.
I would expect the following piece of code to print q whenever the Q key is pressed and Enter whenever the Enter key is pressed. It should also print keypress whenever any key is pressed.
const blessed = require('blessed');
const screen = blessed.screen({
smartCSR: true,
title: 'Title',
});
screen.key('q', () => console.log('q'));
screen.key('Enter', () => console.log('Enter'));
screen.on('keypress', () => console.log('keypress'));
screen.render();
The actual behavior is that if any "printable" key (such as alphanumeric characters) is pressed then that key is just written to the console (just as if it was typed regularly). keypress is not printed either.
The behavior is slightly different for the Enter key. Enter is still not being printed, but keypress is.
Is there anything wrong with my setup? I am using the default Gnome terminal under ArchLinux. However, that should not cause an issue because the program json-log-viewer, which is also blessed-based, works just fine.

The problem was with nodemon, fixed by passing the flag -I. See here.

Related

Detect Key Press in System

I am trying to detect a keypress event outside the console tab, I have allready tried input-event (for linux), hotkeys-js (for browser), and iohook (gives error). How can I do it?
I found a way. I used iohook, but the version 0.6.6 since the new version crashed, and called the start method.
iohook.on('keypress', (res) => {
let key = String.fromCharCode(res.rawcode);
console.log(key);
});
iohook.start();

How do I use the Ace dialog to show messages/errors?

I use the ace editor with the vim keybindings on my site. Whenever someone goes into normal mode and types a command, it shows up in a dialog at the bottom. I defined a function like so:
ace.config.loadModule("ace/keyboard/vim", m => {
m.CodeMirror.Vim.defineEx("write", "w", () => submitForm())
})
The neat thing is, whenever that function errors, it shows the error in another dialog. My question is, is this feature exposed to users? Can I use that dialog to show messages like the editor does when the function errors? Here's a screenshot to show an example:
Typing a command -
Error pops up (another dialog in front of the one that I use to type the command) -
there is no documented api for this, but judging by
https://github.com/ajaxorg/ace/blob/v1.4.9/lib/ace/keyboard/vim.js#L4983, it should be possible to use the following
editor.state.cm.openNotification(domNodeOrHtmlString, {bottom: true, duration: 5000})
to create the dom node you can use the buildDom function from ace.
var domNode = ace.require("ace/lib/dom").buildDom(["span", {style: "color:red"}, "xxxxx"])

Error when trying to send text to application with Pywinauto: AttributeError

I am using Pywinauto to automate some interaction steps with an application that opens during a browser login session.
Lets call the application program.exe. It is actually a Chrome Extension that opens and prompts for a password.
import pywinauto as pwa
from pywinauto import application
from pywinauto import keyboard
app = application.Application()
app = app.Connect(path=r"C:\path\program.exe")
win.Part.Click() #not completely sure why i do this
app['Insert password']['Edit'].send('password')
It seems that I am able to connect to the program, but when I try to send text to the program I get an error. When i run the above this error occurs:
AttributeError: Neither GUI element (wrapper) nor wrapper method 'send' were found (typo?)
If i replace this:
app['Insert password']['Edit'].send('password')
With this:
app['Insert password'].SendKeys.send('password')
I get this error:
MatchError: Could not find 'SendKeys' in 'dict_keys(['Insert password for MyName:Static', 'Static', 'Insert password for MyName:Edit', 'Edit', 'OK', 'OKButton', 'Button', 'Button0', 'Button1', 'Button2', 'Cancel', 'CancelButton', 'Insert password for MyName:Static0', 'Insert password for MyName:Static1', 'Insert password for MyName:Static2', 'Insert password for MyName:', 'Static0', 'Static1', 'Static2'])'
There is no method send for any of the controls. SendKeys is not a method, but a function inside module keyboard so the correct usage is keyboard.SendKeys('password').
But method .type_keys('password') puts the control into focus and then does the same as keyboard.SendKeys. You may need to use with_spaces=True if password contains spaces. Special symbols like % must be escaped so: {%}. This method is powerful because it supports hot key combinations with Alt, Shift, Ctrl etc. See the docs about keyboard module. Usage for your case:
app['Insert password']['Edit'].type_keys('password', with_spaces=True)
Method .set_edit_text('password') can be even more useful: it doesn't type keys char by char, but sends the whole raw text to the control (no support for special keys, just text). This method doesn't require the control to be in focus.

Raw keyboard capture with process.stdin doesn't work as expected?

I'm having problems capturing Raw keyboard input in a terminal on windows. This is driving me crazy, because I know that I had implemented this with older versions of nodejs (a year + ago)
Using the latest versions of NodeJS (currently using 4.2.2), capturing input seems buggy.. Unless I am missing something?
What I am running:
stdin = process.stdin;
stdin.on('data', function (data) {
if (data == '\u0003') { process.exit(); }
process.stdout.write('Captured Key : ' + data + "\n");
});
stdin.setEncoding('utf8');
stdin.setRawMode(true);
stdin.resume();
What I am expecting:
Immediately after running, the program should react to whatever key is pressed, and output:
Captured Key : T
Captured Key : E
Captured Key : S
. . . etc
What I am getting:
After running the program, the first keyboard input, acts as if it is NOT captured in Raw and it is captured and displayed on screen.
Then when I press the ENTER key, the text I just typed gets pushed to the handler function, AND THEN the program will accept further input in raw as expected.
Looks like as if the program requires an ENTER keystroke to initiate a proper raw mode input mode?
pic related: I typed TEST (ENTER). Then the program works as expected.
Anyone knows what is this all about? I can't find anything. Also I don't want to use any external libraries. Thanks!

want to auto click cancel in prompt in firefox

OK so i currently play a game that has a random "bot-check" pop up in
the tab in the pop up it has a "OK" and "cancel" button and I'm trying
to find or make a grease monkey script to auto click "cancel" when it
pop's up and since its random it needs to be a always on type script
the prompt always shows up in the same x and y co-ordinates and button 1 is always OK and button 2 is always cancel hitting escape works just the same as hitting cancel
ive tried google and i cant find anything
// #require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
$(".popup").bind('show',function(){
$(this).hide();
});
may work, depends on the popup type.
if it doesn't work, try this:
// #require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
$(".popup").bind('show',function(){
$(".popup .cancel).trigger("click");
});
[if JQuery wasn't successfully installed in your script previously, you'll need to uninstall your script and reinstall it]
edit: for imitation of pressing escape, use
// #require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
var esc = $.Event("keydown", {
keyCode: 27
});
$(".popup").bind('show',function(){
$('body').trigger(esc);
});

Resources