How to use special characters on keyboard without pressing shift key? - keyboard

How can I use number keys on top of the keyboard just for special characters like (##$) without pressing the shift key to use that? For example, when pressing the num2 key, just show #; I searched about that and understood can do that with AutoHotkey, but I don't find a script to do that, which is no problem. I just want to use numeric keys located at the top of the keyboard. Use that just for special characters.

Steps :
1-Go to AoutoHotkey website and download AutoHotKey its size is
about 3 megabytes.
2-After installing AutoHotKey, right-click on the desktop, select the new AutoHotkey
script, and select that to create a new fileName.ahk
3-Copy this on your .ahk file:
`
1::!
2::#
3::#
4::$
#CommentFlag // 5::%
6::^
7::&
8::*
9::(
0::)
'::"
`
4-Save your file and close it.
5-Right-click on your file and click run Script, or just double click.
If you want to close it, you can do that on task manager.
every time your pc shot down or restarted,ed you should run that script again
your AuotoHotKey flie shuold be like this =
Meanwhile, you can do other cool things : Read This

Related

Script to paste a specific string into a text field with a hotkey

I am trying to find a way to paste a predefined string upon entering a specific keyboard sequence, on any app.
For example if I have to paste an url or a password into a field, I can have said password in a hidden script and when I press, say, [ctrl] + [5], it would write "example123" on the text field where my cursor is.
Ideally without copying to the clipboard (I'd prefer keeping what I have on my clipboard and also avoiding to paste a password or such by mistake elsewhere).
I have tried every solution I've found so far that include xclip, xdotool and xvkdb. All of them either do not work or are really inconsistent: They only paste the string sometimes, and when they do, it's usually only part of the string ("ample123" instead of "example123").
I thought of using compose key, which I heavily use anyway to write in french on an us keyboard, but it seems it only supports 1 character sequences, as nothing is printed when I modify my .XCompose to include custom output sequences of len > 1.
I am using Ubuntu 18.04 with Gnome as a DE. Ideally something that also works when logging back (like compose keys).
You need to walk the Document Object Model for either Gnome or your web-page. My concern is that with a desktop script you wont be able to access the web page because you will need to be able to establish a target to send string to. I see in your question that you tried using using "x{tool-name}" to grab the text field element. Delivering the sting really isn't the problem. The problem is getting the GUI element of text box pragmatically. The easiest way to get access to this in a user loaded web-page is with WebExtensions API which is how to make extensions for most modern browsers. Otherwise, if you can get away with only having access to Gnome's GUI I would try LDTP, it's a library used for testing, but it looks like it can be used for automation too.
For keyboard shortcuts:
It really shouldn't matter what the script is doing to how you want to activate it. I would just go to Gnome/Settings/Keyboard and set the path to where I saved the script to be the Command. If you go the WebExtension route, you will want to build the shortcut into your extension.

Sublime text multiple cursors?

Sublime Text is so damn advanced and this seems like such a stupid question, but...
I started writing a for loop in PHP (using SFTP), loved that it gave me a choice to auto-generate the loop. However, it enters this weird multi-cursor mode, which
1)I am not really sure how to use/exit without using the mouse;
2) it seems useless, seeing as all 3 type the same thing, even though I need to change, for example, the $i > x or $i = x.
Although Sublime does indeed support the idea of multiple cursors (which is an incredible time saver and useful as all get out, as we're about to see), what you're actually asking about here is a snippet which in this case happens to also include multiple cursors.
The general idea is that for code that you're likely to type many times (e.g. a for loop), you can create a snippet that will generate the bulk of the text for you in one shot, and then allow you to easily customize it as needed. In this case, the snippet in question is part of the default functionality of Sublime and is provided by the shipped PHP package.
To answer point #2 in your question first, this is far from useless. As seen here, I enter the text for and then press Tab to expand the snippet out. The first thing to notice here is that the status line says Field 1 of 4 to tell me that I'm in a snippet and that it contains four fields.
The first field is the name of the control variable for the loop, and all of them are selected so that as I change the name, all of them change at the same time because when there are multiple cursors, the text you type appears at all of them at the same time.
Once I'm done changing the name of the variable, I press Tab again to go to the next field, which allows me to easily change the point at which the loop starts. Another press of Tab takes me to the third field, where I can specify where the loop ends.
One last press of Tab exits the snippet and selects the text in the loop, so I can start writing my code (caveat: I am not a PHP developer).
At this point you can see Sublime offering another snippet for echo, which would expand out to an echo statement complete with quotes, then allow me to edit the text in the echo and skip to the end.
Circling back around to the first point in your question, you can use Esc at any point to jump out of a snippet and go back to regular editing. You can also use Tab or Shift+Tab to move through the fields in the snippet, and pressing Tab at the last field in the snippet exits it as well.
In this particular case, the first field in the snippet sets up multiple cursors, and so exiting the snippet while this field is active leaves multiple cursors in effect. You can jump back to a single cursor by pressing Esc one more time (this is true regardless of how you ended up with multiple cursors).

How can I enter text into Launchy and append it to the end of a text file?

I'm a Debian Stretch user coming from Windows. In Windows with the launchy app (also available for Linux), I had a method of entering text into launchy that was then appended to the end of a .txt or .md file.
To do this in Windows, I created a file called note.bat that contained the following:
echo %*>>"C:\collectednotes.md"
I'd make launchy aware of note.bat by adding its containing folder to “Launchy” → “Settings” → “Catalog” and adding filetype *.bat.
From there, I'd launch launchy, type note, hit Tab, enter some text, hit Enter, and then the text would be added to the end of collectednotes.md.
A mostly working process is detailed in my answer below. I'll give the green checkmark answer to anyone that can adjust this process (via note.sh and/or launchy plugin setup detailed below) to appropriately handle all special characters.
This may contain the solution to this question:
Which characters need to be escaped in Bash? How do we know it?
Solved (almost). I'm keeping this question unanswered and will give to whoever completes the remaining ~5%. Steps to get the 95% solution with xfce4-terminal version 0.8.3-1:
Install launchy and launchy-plugins (both are version 2.5-4 for me):
apt-get install launchy
apt-get install launchy-plugins
Open terminal to default location of ~/ and create collectednotes.md:
echo "# Launchy Notes Collected Here" > collectednotes.md
Create note.sh shell script:
echo '#!/bin/sh' > note.sh
Create shell script line 2:
echo ALL_ARGUMENTS='"$#"' >> note.sh
Create shell script line 3:
echo 'echo "$ALL_ARGUMENTS" >> ~/collectednotes.md' >> note.sh
If you open note.sh, it will look like:
#!/bin/sh
ALL_ARGUMENTS="$#"
echo "$ALL_ARGUMENTS" >> ~/collectednotes.md
Make note.sh executable:
chmod +x note.sh
Launch launchy and click the gear icon in upper right for settings. If consistency with launchy for Windows is desired, set launchy Hotkey to Alt+Space. If you receive a keyboard shortcut conflict message as I do on Debian with Xfce, first go to Settings, Window Manager, Keyboard tab, and clear Alt+Space as the shortcut for Window operations menu.
Next in launchy settings, go to Plugins tab and enable the plugin Runner. Click the + button and create a new Runner custom command as follows:
- Name: note
- Program: /home/YOURUSERNAMEHERE/note.sh (launchy does not like Program path of ~/note.sh, so a specific path with username is required)
- Arguments: '$$'
Click the Catalog tab and hit Rescan Catalog just in case. Hit OK to close launchy settings.
Now let's test it.
- launch launchy with Alt+Space or your hotkey
- type note (You may have to wait 10 second or so on first run. You'll know things are as expected when you see the text "note" with a orange/yellow icon containing silhouette of a person.)
- hit Tab
- enter some text (no need for single or double quotes or escapes), e.g.: Remember to donate at least $3 to Josh at Launchy https://www.launchy.net/donate.php
- hit Enter
Now open collectednotes.md to confirm the text was captured.
The remaining issues seem to be dealing with single quotes and double quotes. For example, consider the following note:
I don't know what I'd do without Launchy.
Which results in the following in collectednotes.md:
I dont know what Id do without Launchy.
Or:
Would David Allen like universal text capture from anywhere in Linux? My bet is "yes!"
Results in the following in collectednotes.md:
Would David Allen like universal text capture from anywhere in Linux? My bet is \yes!\
Single quoting and/or double quoting the input to launchy doesn't solve it. Note the launchy Runner custom plugin construction component of '$$' is a piece of this puzzle.
I'll give the answer to anyone that can adjust this process (via note.sh and/or launchy plugin setup) to appropriately handle all special characters. Maybe this would add proper escapes to user input with something like gsub.
The rationale for being exacting regarding proper character handling is that this process is useful for copying and logging random chunks of text from web pages, but if common characters like single quotes are not handled as expected, confidence in the system is much reduced.

pywinauto (or others): to emulate Ctrl+A & Ctrl+X anywhere (not only on specified app)

I'm looking for a way to generate a ctrl+A (select all), and then ctrl+x in a python script. I know how to generate this in a specific app (pywinauto and other modules do that). But I'm looking for a way to send these keys in any apps (in any field of the active windows). I want to launch the python script containing these keys anywhere (the script will be launch using a key shortcut. Details below (1))
EDIT: I'm NOT trying to copy/past in the command windows (cf. the 2 last sentences). My script send the keys in the command windows, but that's the problem I'm trying to solve...
Using python pywinauto (or Ctypes or other modules)
I tried several propositions listed here with the same result.
I thought pywinauto could do it. Following pywinauto latest documentation I tried that:
open an (any) app containing a text field (that's the active windows)
place the cursor where you want to make the select all + cut/past
run the script bellow using an shortcut (so you won't leave the active windows)
from pywinauto.keyboard import SendKeys
SendKeys('^a^x')
Result
The code only print ^A^X in the python console. It doesn't do what it's suppose to do in the field of the active window (where I placed my cursor): it doesn't select all + cut the text.
Using autohotkey:
The only way I found to simulate a real crtl+A ctrl+C is by using autohotkey (it works but it's not a python solution):
save the code bellow in my AHK script: select_copy.ahk
Send, ^a
Send, ^x
create another AHK script called shortcut.ahk where you will specify a shortcut to launch select_copy.ahk (shortcut.ahk sould run constantly in windows background (2))
!^+G:: Run select_copy.ahk , C:\Users\Me\Desktop
(meaning: when I hit ctrl+alt+shift+G run the script select_copy.ahk)
result:
It works. when I call the ahk, it select/cut things in the active windows.
A combination of both did not work
I tried to launch the select_copy.ahk from within a python script (using subprocess.call) but I ended up with the same result than pywinauto (or Ctypes): it only prints ^A^X in the consol, but doesnt select&cut. So I'm wondering if python could really do what autohotkey does.
(1) What the script will do: I will launch the script (using a shortcut key) on one or another html editor, it will cut all the text, parse its source code, make some change put back the datas in the clipbboard, and past it. I'm only missing the first part (select all + cut) and the last part (past).
(2) It's not the big deal since shortcut.ahk contains also all my other ahk shortcuts and scripts.
Your AutoHotKey script should work, and does on my machine. However, I recommend that you just have one shortcut.ahk file containing the following:
!^+G::
Send, ^a
Send, ^x
Return
...and then put this in your python file:
subprocess.call("C:\\Path\\To\\AutoHotKey.exe /r C:\\Path\\To\\shortcut.ahk")
replacing the paths with wherever the AutoHotKey executable is, and wherever the shortcut.ahk file is.
Just as a side note: !^+G:: triggers on Alt+Shift+Ctrl+G, not Shift+Ctrl+G as you wrote in your question:
(meaning: when I hit ctrl+shift+G run the script select_copy.ahk)
EDIT: Also, from the phrase in the python console in your question it seems like you're trying to select all and then cut it in CMD. This will not work at all. Instead, if you want to simply clear the console, just use the command cls (Windows only; use clear in Linux). If you want to copy the entire console output and then clear it (i.e. cut) you're gonna need something different.

Is there a simple way to read scancodes from the keyboard without involving third-party libs?

I'm trying to build a shell project in Rust and I ran into trouble in the very beginning. Instead of reading the whole line and output through stdin/stdout, I want to parse every keypress and maintain a buffer until Enter is pressed. With an ability to move the cursor, backspace, access command history by up/down keys etc.

Resources