Send key press FROM keyboard without physically pressing any keys - not simulate - keyboard

I need to send a key press from the keyboard without manually/physically touching the keyboard.
I DON'T want to simulate key press events using SendKeys, or using AutoHotKey, etc. I need the signal to come from the keyboard's usb cable.
This script,
' Open notepad
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad", 9
' Give Notepad time to load
WScript.Sleep 500
'press some letters and capslock
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{CAPSLOCK}"
types the message, Hello World!, and 'presses' the capslock key causing the capslock led to light up (or turn off depending on the starting position). So I assume I am able to send a signal to the keyboard. How do I get the signal to be sent back?

Related

How to detect key press on a terminal while not actually generating those keystrokes as inputs? PYTHON

My goal was to have the user presses 2 keys at the same time to continue the program. However, in my actual code, there is an input prompt following the detection of the keystrokes. Then, those 2 keys will appear on the in-line text field, then the user has to erase that before proceeding.
I have created a minimal single script to recreate that behavior:
import keyboard
import time
print("Running keyboard script")
while True:
try:
if keyboard.is_pressed('z') and keyboard.is_pressed('p'):
print('z and p press')
time.sleep(1)
something = input("Type something:") # `zp` will appear in this prompt
except KeyboardInterrupt:
print("Exiting")
break
I mean the user can just hit backspace twice to erase that, but I want to automate that part. A solution that I came up with was to use backspace characters as a workaround:
import keyboard
import time
print("Running keyboard script")
b = '\b,'*100
b+='\b'
while True:
try:
if keyboard.is_pressed('z') and keyboard.is_pressed('p'):
keyboard.press_and_release(b) # I added this as a workaround, however, it introduces different behavior
print('z and p press')
time.sleep(1)
something = input("Type something:")
except KeyboardInterrupt:
print("Exiting")
break
This solution seems to work if and only if the user's active window is the terminal. If the user clicks away to a different window, the backspace key press will be sent to the keyboard controller and it will erase 101 characters of the other focused window, for instance, if they click away to a text editor, then 101 characters would be erased. 101 characters is just a magic number that I came up in case they pressed more than the two keys that I asked.
So, I wonder if there is a better solution to just detecting the keyboard press while blocking them from being sent to the input prompt? I have tried, sys.stdin.read() but apparently, it won't read anything until the contents have been entered. Also, tried io.StringIO(sys.stdin.read()), which behaves similar to sys.stdin.read()

Allow hotkey that presses a disabled key

My keyboard key/letter f is ruined and continuously presses the letter. I am using AutoHotKey to successully disable the letter, but I need an alternative hotkey to press the key. I have chosen to use CTRL+j as the hotkey to press the letter f. I tried this script but it does not seem to press the key:
f::return
^j::
Send f
return
I also tried this but it also does not work:
f::return
^j::
Send {f down}
return
How can I get the script to press f using the hotkey CTRL+j, while disabling the key f?
The $ modifier is going to solve this problem.
That modifier makes it so that your f::return hotkey wont affect keys that are sent from AHK.
So here's your finished script:
$f::return
^j::SendInput, f
Also switched over to SendInput due to it being the recommended faster and more reliable send mode.
I used the ASCII code for the letters in both uppercase and lowercase, and it also worked:
; disable the key 'f':
f::return
; press CTRL+j to press f:
^j::
Send {Asc 102}
return
; press CTRL+Shift+j to press F:
^+j::
Send {Asc 70}
return

POS thermal printer drawer kicks only first time

I'm using the lp command to print stuff to a thermal POS printer. All works fine when I'm printing formatted text and doing cuts.. etc. However, when I send the Drawer Kick command ESC p 0 25 250 it kicks the drawer and then I cannot print or kick after that without having to reset the printer.
Has anyone had this problem and do you know the fix?
What I've noted is all the commands that I send to the printer have a start command and an end. For example, to turn bold text on I have
ESC E \x01 and to turn it off I have ESC E \0, \0 being the null character. But the drawer kick command doesn't have the null character at the end, could that be screwing the printer queue for some reason? Maybe printer is expecting an end to the command somehow?
Can anyone help please?

Enable destructive backspace in Teraterm

I have an application that communicates via USB over COM and I usually use Putty to develop. Some of the users will use Teraterm instead and want the user experience to be as similar as possible.
In Putty, I can send a 0x7F which is ASCII "DEL" and when that value is echo'd back from my application, Putty does a backspace+delete (destructive backspace). With Teraterm, Backspace sends 0x08 which is ASCII "BS" (backspace) and, as long as the "Transmit DEL by:" box for Backspace Key is not checked, the key is returned as 0x08 without any delete (non-destructive backspace).
Is there any way to enable configuration of Teraterm to move cursor position back one character and delete that character when it receives the 0x08 command?
This has been a long time with no answer, so hopefully you worked through it. I don't understand if this scripted through the teraterm macro or if you are just manually navigating through teraterm.
But if this is for a script (.ttl) file or just a command within teraterm, and you know what string is being sent that needs this, you can do the following:
wait "[insert string you are looking for here]"
send 8 127
Where 8 means backspace and 127 means delete. Hope that helps. But teraterm will accept multiple ascii codes in one send command. The wait command could also be further rounded out to accept a timer for the wait action before it performs anything. The wait command can also accept up to 10 strings to wait for: https://ttssh2.osdn.jp/manual/en/macro/command/wait.html
You can also find the ASCII code table for teraterm here: https://ttssh2.osdn.jp/manual/en/macro/appendixes/ascii.html

Using Autohotkey to add an artificial delay to a keypress

I am trying to use autohotkey to add an artificial delay to a keypress. I am in a tiled room, with a mechanical keyboard, and a desktop microphone. I would like to add an artificial delay of approximately 1/10 of a second to my PTT key, so that others don't hear the audible CLICK when I press the key. I ended up binding the key to something else "numpad -" so that capslock could be the key I actually press. This is the script I ended up with.
Expected result: pressing capslock presses numpad- on a 0.1s delay, and then holds the key until I release capslock(and it should also unpress capslock on release)
Actual result: It works, but if I press and release it too quickly, it holds "numpad -" down and capslock down, and releases neither.
code:
#UseHook
*~Capslock::
sleep, 100
Send {NumpadSub Down}
sleep, 100
While GetKeyState("Capslock")
{
}
return
*~Capslock Up::
sleep, 300
Send {NumpadSub Up}
return
without the sleeps as is, the program opens the key, closes the key, and then re-opens.
UseHook
Answer:
*~Capslock::
sleep, 100
Send {NumpadSub Down}
keyWait, Capslock, U
sleep, 100
Send {NumpadSub Up}
return

Resources