Is it possible within the context of an ANSI Terminal (or an emulator, it can be of any flavor) to draw two characters over one-another? Or, at least, is there a way to print a character and a bar on top of it (like underline, with line up)?
It is impossible to draw characters one over another in terminal. It is simply against the basic principle of terminal where each cell contains 1 cahracter.
If your terminal supports unicode, there are special unicode characters called combining characters, one of which is overline. Its code is U+0305. So, using this, you can draw an overline on another character.
Here is a sample C code that does it
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main() {
setlocale(LC_CTYPE, "");
for (wchar_t ch = 'a'; ch <= 'z'; ++ch) {
wprintf(L"%lc\u0305 ", ch);
}
}
should yield something like that
a̅ b̅ c̅ d̅ e̅ f̅ g̅ h̅ i̅ j̅ k̅ l̅ m̅ n̅ o̅ p̅ q̅ r̅ s̅ t̅ u̅ v̅ w̅ x̅ y̅ z̅
Thats about as close as it gets to what you want.
Related
I'm writing a console app that requests a password and I'd like to use the same symbol as the macOS ssh command, but it doesn't show up in the Character Viewer (⌘⌃Space) under the word KEY. The closest is 🔑or 🗝. Seems to be Mac specific as I don't see it in the source code for OpenSSH. Anyone know to produce this symbol?
That's not a character, it's the insertion point (the text cursor), and it's drawn by the terminal app, not ssh. It looks like you're using iTerm; if you run this in Terminal, you'll see that it displays a different icon. The key icon you're looking for is in iTerm's Resources folder (key.tiff).
The key cursor gets enabled whenever ECHO is turned off on the terminal. For example, in C:
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
int main (){
struct termios termInfo, save;
// Fetch the current attributes
if (tcgetattr(STDIN_FILENO, &termInfo) == -1) {
perror("tcgetattr");
exit(1);
}
save = termInfo;
// turn off ECHO, and ECHONL on
termInfo.c_lflag &= ~ECHO;
termInfo.c_lflag |= ECHONL; // echo newline even if echo is off
// Set it
tcsetattr(STDIN_FILENO, TCSASOFT|TCSADRAIN, &termInfo);
printf("Password: ");
// Consume characters until the user presses enter
while (fgetc(stdin) != '\n') {}
printf("Accepted\n");
// Set it back to the original values
tcsetattr(STDIN_FILENO, TCSASOFT|TCSADRAIN, &save);
}
This will display the key icon you're looking for.
I'm a beginner using Arduino with a Teensy 3.2 board and programming it as a usb keyboard.
I have two 4 button membrane switches. Their button contacts are on pins 1-8, and the 9th pin holds a soldered together wire of both membrane switches' "ground" line or whatever it's true name is; the line that completes the circuit.
Basically when you press the buttons they are supposed to simply type "a, b, c..." respectively. I've been told I need to use a matrix for this.
I'm looking for an example of how to code a keyboard matrix that effectively supports a one row/9 column line (or vice versa?) I've been unable to find that solution online.
All I have so far is this code which, when the button on the second pin is pressed, sends tons of "AAAAAAAAAAAAAAAA" keystrokes.
void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
//if the button is pressed
if(digitalRead(2)==LOW){
//Send an ASCII 'A',
Keyboard.write(65);
}
}
Would anyone be able to help?
First of all, a 1-row keypad is NOT a matrix. Or better, technically it can be considered a matrix but... A matrix keypad is something like this:
You see? In order to scan this you have to
Pull Row1 to ground, while leaving rows 2-4 floating
Read the values of Col1-4. These are the values of switches 1-4
Pull Row2 to ground, while leaving rows 1 and 3-4 floating
Read the values of Col1-4. These are the values of switches 5-8
And so on, for all the rows
As for the other problem, you are printing an A when the button is held low. What you want to achieve is to print A only on the falling edge of the pin (ideally once per pressure), so
char currValue = digitalRead(2);
if((currValue==LOW) && (oldValue==HIGH))
{
//Send an ASCII 'A',
Keyboard.write(65);
}
oldValue = currValue;
Of course you need to declare oldValue outside the loop function and initialize it to HIGH in the main.
With this code you won't receive tons of 'A's, but however you will see something like 5-10 'A's every time you press the button. Why? Because of the bouncing of the button. That's what debouncing techniques are for!
I suggest you to look at the class Bounce2 to get an easy to use class for your button. IF you prefer some code, I wrote this small code for another question:
#define CHECK_EVERY_MS 20
#define MIN_STABLE_VALS 5
unsigned long previousMillis;
char stableVals;
char buttonPressed;
...
void loop() {
if ((millis() - previousMillis) > CHECK_EVERY_MS)
{
previousMillis += CHECK_EVERY_MS;
if (digitalRead(2) != buttonPressed)
{
stableVals++;
if (stableVals >= MIN_STABLE_VALS)
{
buttonPressed = !buttonPressed;
stableVals = 0;
if (buttonPressed)
{
//Send an ASCII 'A',
Keyboard.write(65);
}
}
}
else
stableVals = 0;
}
}
In this case there is no need to check for the previous value, since the function already has a point reached only when the state changes.
If you have to use this for more buttons, however, you will have to duplicate the whole code (and also to use more stableVals variables). That's why I suggsted you to use the Bounce2 class (it does something like this but, since it is all wrapped inside a class, you won't need to bother about variables).
I've been tying to build a simple Win Api program (using CodeBlocks) and ran into a weird problem.
case WM_COMMAND:{
if (LOWORD(wParam) == Calculate) {
int A=0, ArrayReset = 0;
char textread[256];
SendMessage((HWND)Box1,(UINT) EM_GETLINE, (WPARAM)1, (LPARAM)&textread);
A = atoi(textread);
itoa(ArrayReset, textread, 10);
itoa(A, textread, 10);
SendMessage((HWND)Box1,(UINT) WM_SETTEXT, (WPARAM)1,(LPARAM)&textread);
(My program is a bit more complicated, but this is just to show the problematic point)
Now, what I expect the code to do is to read the value in Box1, convert it into integer, convert it back to char array, and print this array back on the same Box1. Basically, some converting with no difference in the end result.
However, there is this strange problem. The code works with single digit numbers just fine, but if I enter a number with more digits, like 12 or 356, I get 1200 and 3560 respectively. If the input number is bigger than a thousand, it works fine again.
Is this a problem because of my method of resetting array's value back to 0, or does it have to do something with the conversion processes?
There are some mistakes in this code.
For starters, (LPARAM)&textread should be either (LPARAM)textread or (LPARAM)&textread[0].
But more importantly, you are not preparing the EM_GETLINE message correctly:
lParam
A pointer to the buffer that receives a copy of the line. Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters. The size in the first word is overwritten by the copied line.
Try this instead:
case WM_COMMAND:{
if (LOWORD(wParam) == Calculate) {
int A = 0;
TCHAR textread[256];
*((LPWORD)&textread) = 256; // <-- add this
SendMessage(Box1, EM_GETLINE, 0, (LPARAM)textread);
_stscanf(textread, _T("%d"), &A);
_stprintf(textread, _T("%d"), A);
SendMessage(Box1, WM_SETTEXT, 0, (LPARAM)textread);
}
break;
I think you have several problems there.
First, you didn't show us what Parse1 is. Beware that you must set the size of the buffer in the first word of the buffer. Also, why do you pass 1 as the WPARAM? This is the zero-based index of the line to retrieve from a multiline edit control, but is ignored if the edit is single line.
Also, what is with the first itoa call?
Here is an example that works:
TCHAR textread[256] = {0};
*(reinterpret_cast<WORD*>(&textread)) = 256;
::SendMessage(hwnd, EM_GETLINE, 0, reinterpret_cast<LPARAM>(&textread));
auto n = _ttoi(textread);
_itot_s(n, textread, 256, 10);
::SendMessage(hwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(&textread));
I'm using the following command to print a justified text:
^FB1800,3,0,J^FT100,200^A0B,26,26^FH\^FDLONG TEXT TO BE PRINTED, WHICH DOESNT FIT IN ONLY 3 LINES...^FS
The command ^FB1800,3,0,J prints a field block in a width of 1800 dots, maximum 3 lines, justified.
The problem is that if the text exceeds the maximum number of lines, it overwrites the last line! :( That of course makes the text of the last line unreadable.
How can I avoid that? Does anybody know if is there a way to cut the exceeding text?
The documentation says exactly that this happens:
Text exceeding the maximum number of lines overwrites the last line. Changing the font size automatically increases or decreases the size of the block.
For reference: I'm using printer Zebra 220Xi4.
Any help would be appreciated. Thank you!
Take a look at the ^TB command. It is preferred over the ^FB command and truncates if the text exceeds the size defined in the TB params
I had just about the same problem, what fixed it in my case - although not the most elegant way - is to specify a higher number of maximum lines, and then formatting it in a way that only the first 3 are in the visible area.
In your case it would be for example ^FB1800,7,0,J instead of ^FB1800,3,0,J
This at least fixed it for me right away, because I print this text at the bottom of the label. If you need to have it somewhere in the middle or top, there might be some tricks with putting a (white) box on top of the overflow-area, since the Zebra printers seem to render before printing. Hope it helps.
Depending on the higher-level programming language you're using (assuming that you are), you could accomplish the same thing (truncate the text to be printed to a specified number of characters) with code like this (C# shown here):
public void PrintLabel(string price, string description, string barcode)
{
const int MAX_CAPS_DESC_LEN = 21;
const int MAX_LOWERCASE_DESC_LEN = 32;
try
{
bool descAllUpper = HHSUtils.IsAllUpper(description);
if (descAllUpper)
{
if (description.Length > MAX_CAPS_DESC_LEN)
{
description = description.Substring(0, MAX_CAPS_DESC_LEN);
}
}
else // not all upper
{
if (description.Length > MAX_LOWERCASE_DESC_LEN)
{
description = description.Substring(0, MAX_LOWERCASE_DESC_LEN);
}
}
. . .
This is what I'm using; is there any reason to prefer the "raw" ^TB command over this?
I've got some older MFC code I wrote that I'm "freshening up" a bit. I have the following code in a window class' OnChar() handler.
I really don't like using constants like 0x18. I'd like to make the code more readable. I know I can declare my own, but are there no Windows macros for these values? I couldn't find anything about this on the web.
// Check for clipboard commands
switch (nChar)
{
case 0x18: // Ctrl+X - Cut
OnEditCut();
break;
case 0x03: // Ctrl+C - Copy
OnEditCopy();
break;
case 0x16: // Ctrl+V - Paste
OnEditPaste();
break;
}
Do you have some code above there which is subtracting an offset from nChar?
Those values are the letters' places in the alphabet, but I don't think character codes normally work like that. (It has been a long time since I used any of this so maybe I'm just mis-remembering.)
Anyway, the code fragment you have is effectively this (at least on architectures that use the ASCII character ordering, i.e. alphabetic):
// Check for clipboard commands
switch (nChar)
{
case ('X' - 'A' + 1): // Ctrl+X - Cut
OnEditCut();
break;
case ('C' - 'A' + 1): // Ctrl+C - Copy
OnEditCopy();
break;
case ('V' - 'A' + 1): // Ctrl+V - Paste
OnEditPaste();
break;
}
As mentioned in my other comment, I'd expect there to be some other code checking for Ctrl being held down.