Multi Clicks With the Same Keyboard Shortcuts to Run a Ahk Script - keyboard

I want to do Multi Clicks with the same Keyboard Shortcuts to Run a Ahk Script.
I now in Autohotkey Languages, you can write a code that can execute a part of Code, if a certain Keyboard Shortcut combination is pressed.
But i want on my Windows System, to Click a count of the same keystroke combinations to execute a part of Code.
The pros are: you do not have to move your fingers to a other place on that keyboard, Click it again and it will run a other Code. (this will improve my keyboard Movements and i have more options to do keystrokes.)
Example:
Click - Ctrl + (1x)c - to CopyText
DoubleClick - Ctrl + (2x)c - to CopyText + GoogleSearch
multiClick - Ctrl + (5x)c - ?
If you look to this Example Script then you can see what i mean.
(note - Hotkey > [^cc::] or hotkeystring > [:*:^cc::]- this does not work, is there another way to solved this)
; [+ = Shift] [! = Alt] [^ = Ctrl] [# = Win]
#SingleInstance force
;MultiClicks the Same Keyboard Shortcuts to Run a Ahk Script
;Click Ctrl + c to [copy text]
^c::
send ^c
;msgbox script1
return
;DoubleClick Ctrl + (2x)c [copy text] + [do a google search]
^cc::
send ^c
sleep 200
run https://www.google.com/?q=%clipboard%
;msgbox script2
return
;MultiClicks Ctrl + (5x)c to run script5
^ccccc::
;?
;msgbox script5
return
esc::exitapp

^c::
{
count++
SetTimer, actions, 400 ;время за которое нужно нажать комбинацию
}
return
actions:
{
if (count = 1)
{
msgbox CTRL+C
}
else if (count = 2)
{
msgbox CTRL+CС
}
else if (count = 5)
{
msgbox CTRL+CСССС
}
count := 0
}

Related

Python -- Adding string to clipboard that will paste to Excel in proper format (i.e., separated into rows/columns)

I've seen a few answers to this problem, but in VBA and C#---nothing in python.
In python 3, I'm trying to do the following:
Assign a variable a string of values with appropriate "excel" format
Have this variable then copied to the clipboard
Then the user should be able to manually CTRL+V (paste) this string into excel and have it separate into the correct row/column placements.
I'm using both tkinter and openpyxl for my project and through testing I've gotten some results, but it is not what I want. The closest that I've gotten is below.
# If I first go into excel,
# and copy a few columns within a single row with different data in them,
# then I run the following code:
import tkinter as tk
root = tk.Tk()
paste = root.clipboard_get()
print(paste)
# Then I manually copy the print output to the clipboard,
# and then go back to excel and paste,
# excel gives the following warning message:
# "The data you're pasting isn't the same size as your selection. do you want to paste anyways?"
# And after pressing OK, it seems as though the data is pasted properly.
This is OK, and the print(paste) string might help me create the appropriate format for the initial variable of strings that I want to generate, but I need a solution that will not cause Excel to make this warning sign pop up every time.
If anyone can provide some insight into this, I would greatly appreciate it. Also, the solution needs to be via python not through modifications to Excel. Secondly, the solution is not about appending/writing the data directly to Excel (via Openpyxl, etc) but about getting the data to the clipboard in the appropriate format (I'm using Excel 2016).
Thanks!!
Edit:
I have also tried using the "ctypes solution" presented here by user kichik.
To make this solution easier to work with, I downloaded an app called "InsideClipboard" which lets me easily see the format ID of each types of formats that the clipboard "copies" data in.
Using kichik's ctype solution, I checked to see if manually copying the print output of the different formats stored in the clipboard would let me manually CTRL+V to Excel in the original format, but this failed. The original "copy" was of multiple columns of strings in a single rows of strings from Excel, and the manual "paste" of the individual formats back into excel kept all the strings into a single cell (with the exception of HTML Format that created multiple rows of data--also wrong). The different formats included CF_LOCALE (16), CF_TEXT (1), CF_OEMTEXT (7), CF_UNICODETEXT (13), AND HTML Format (49384).
So, still: no solution.
Edit2:
I realized that I could create strings in python with actual tabs pressed in between the string, instead of using \t, and it worked to create a single string that would place the data into different columns of a single row when pasted into Excel.
Also, I realized that if I CTRL+V directly into Excel (not on the Row heading), on the actual row in which I want to paste the data, I no longer get the Excel "warning message". So, using this work around might work. If no one has any input, then this simple approach might be good enough.
However, I would like to be able to simply click on the row heading instead of the first relevant row cell to paste the data without the Excel warning popup. Ideas are still welcome, and it would be best to have it all done via python (without modifications to Excel as the app may be run on different Windows OS PCs).
So: possible simple solution, but not perfect.
Edit3:
So I've worked out a solution based on Edit2. The Excel "warning" popup still happens if Excel is opened as an app on the working computer; however, if the Excel file is opened and editable via an online processor, then the user can highlight the row heading and paste without generating the Excel "warning" popup. This works in my specific case, although the better solution would be to have the copied data not generate the Excel "warning" popup in any situation. Regardless, if no one knows how to prevent the Excel warning popup through python alone, then I can still work with this method.
Here's my solution (note that the spaces in the long string are actually 'tabs'):
import pyperclip
# t variables are defined prior to the below code
# note: the " " parts in the data string are actually tabs
data = t1 + " " + t2 + " " + " " + t3 + " " + t4 + " " + t5 + " " + t6 + " " + t7 + " " + " " + "t8" + " " + " " + " " + " " + " " + " " + t9 + " " + t10 + " " + t11 + " " + t12 + " " + " " + " " + " " + " " + " " + t13
pyperclip.copy(data)
print("clipboard:", data)
# now manually pressing CTRL+V while inside Excel (online processor) will
# paste the various t variables in the appropriate cells designated by
# the " " tabs in between. Of note, this works for columns of a single
# row as I didn't need multiple rows of data for my task.
Below is code to create a 5 row by 3 column grid of Entries in tkinter. Pressing the copy button copies the content of the Entries as a tab / newline separated string to the clipboard which can then be pasted into excel.
import tkinter as tk
from tkinter import ttk
ROWS = 5
COLS = 3
root = tk.Tk()
rows = [] # Container for Entry widgets.
# Create and grid the Entry widgets.
for row in range( ROWS ):
temp = []
for col in range( COLS ):
temp.append( ttk.Entry(root, width = 10 ))
temp[-1].grid( row = row, column = col )
rows.append( temp )
def entries_to_lists( rows ):
list_out = []
for row in rows:
temp = []
for col in row:
temp.append( col.get() )
list_out.append( temp )
return list_out
def string_out( rows ):
""" Prepares a '\t', '\n' separated string to send to the clipboard. """
out = []
for row in rows:
out.append( '\t'.join( row )) # Use '\t' (tab) as column seperator.
return '\n'.join(out) # Use '\n' (newline) as row seperator.
def do_copy():
data = entries_to_lists( rows )
root.clipboard_clear()
root.clipboard_append( string_out( data )) # Paste string to the clipboard
root.update() # The string stays on the clipboard after the window is closed
ttk.Button( text = " Copy ", command= do_copy ).grid( column = 1 )
# Button to trigger the copy action.
root.title("Copy to Excel Test")
root.geometry("400x200+10+10")
root.mainloop()
This copied into Excel 2013 in Windows 10 with no warning messages.
string_out will generate a suitable string from any list of lists of strings, a 2d list.

Autohotkey remap > and < on italian keyboard

I have a small problem I cant find the solution to:
On my italian keyboard one key holds the two simbols "<" and ">":
[key] = "<"
[shift]+[key] = ">"
I'd like to remap them so that the result ins inverted as I use > much more than <.
I can't find a way to write this in ahk. I tried with
<::>
+>::<
and
<::>
>::<
The result with the above is that both pressing the key and shift+key returns ">".
I understand what "confuses" ahk but I can't find a workaround.
Any suggestions?
Try
#UseHook ; prevents the Send command from triggering the hotkey itself
<:: Send >
+<:: Send <

How Can I paste the content of a text file 400 times

its for a unity research project, I dont want to have to press control v exactly 400 times. I just want to paste it in another .txt file
this is the text
http://pastebin.com/m1u4AFAr
Thank you for you help
Use Unity. Go to that link and copy the text. Run this script in Unity and it will duplicate the text for 400 times and save it. It will show you where it saved it. Any text you have in the clipboard will be duplicated 400 times.
void Start()
{
//Get Clipboard
string fileInfo = GUIUtility.systemCopyBuffer;
if (fileInfo == null)
{
Debug.Log("Clipboard is Empty. Exited");
return; //exit
}
//Multiply by file 400
System.Text.StringBuilder crazyfileX400 = new System.Text.StringBuilder();
for (int i = 0; i < 400; i++)
{
crazyfileX400.Append(fileInfo).Append("\r\n");
}
string filename = Application.persistentDataPath + "/" + "crazyFile.txt";
System.IO.File.WriteAllText(filename, crazyfileX400.ToString());
Debug.Log("File written to " + filename);
}
Have a look at this open source macro-creation and automation software.
You can use it to write a script that does the job for you. Here's a a script for simple copy and paste:
#c::
Send, {CTRLDOWN}c{CTRLUP}{ALTDOWN}{TAB}{ALTUP}
sleep, 300
Send, {CTRLDOWN}v{CTRLUP}{ENTER}{ALTDOWN}{TAB}{ALTUP}
return
You could adapt it to your situation by adding a loop.

Sublime Text - How do I create a keyboard shortcut to move text from one open file to another

Using Sublime Text, I've got blocks of text in a column on the left and I'd like to selectively shift some lines to a separate file on the right.
Is there an existing keyboard shortcut to do this, and if not how would I go about putting one together. The steps would be
1. Cut selection
2. Change to other column
3. Paste selection
I wrote a simple plugin that meets your question's requirements and has a few extra features:
bidirectional copy & cut commands ( from active document to inactive document, works on either view )
selects & scrolls to inserted text # inactive document
only executes if there are exactly 2 view groups
Copy the following code to:
Packages/MoveTextToInactiveDocument/MoveTextToInactiveDocument.py
import sublime, sublime_plugin
LINE_BREAK = "\n"
class MoveTextToInactiveDocumentCommand( sublime_plugin.TextCommand ):
def run( self, edit, MODE = "copy" ):
view = self.view
window = view.window()
#■■■ Verify Window Groups ■■■#
windowGroup_Count = window.num_groups()
if windowGroup_Count != 2:
return
#■■■ Set Active & Inactive Documents ■■■#
activeDocument_Group = window.active_group()
if activeDocument_Group == 0:
activeDocument = window.active_view_in_group( 0 )
inactiveDocument = window.active_view_in_group( 1 )
elif activeDocument_Group == 1:
activeDocument = window.active_view_in_group( 1 )
inactiveDocument = window.active_view_in_group( 0 )
#■■■ Verify Selection ■■■#
selections = activeDocument.sel()
if len( selections ) == 0:
return
#■■■ Move Text From Active Document To Inactive Document ■■■#
first_InsertionPoint = inactiveDocument.size()
for region in selections:
regionText = activeDocument.substr( region ) + LINE_BREAK
insertionPoint = inactiveDocument.size()
inactiveDocument.insert( edit, insertionPoint, regionText )
if MODE.lower() == "cut":
activeDocument.erase( edit, region )
#■■■ Select & Scroll To Inserted Text ■■■#
inactiveDocument_End = inactiveDocument.size()
insertedText_Region = sublime.Region( first_InsertionPoint, inactiveDocument_End )
inactiveDocument.selection.clear()
inactiveDocument.selection.add( insertedText_Region )
inactiveDocument.show( inactiveDocument.size() )
window.focus_view( activeDocument )
Open your user sublime-keymap file by running Preferences: Key Bindings - User from the command palette.
Add the following key-bindings.
{
"keys": [ "ctrl+super+c" ],
"command": "move_text_to_inactive_document",
"args": { "MODE": "Copy" }
},
{
"keys": [ "ctrl+super+x" ],
"command": "move_text_to_inactive_document",
"args": { "MODE": "Cut" }
},
You can now use:
Ctrl + Super + C to copy selections to the inactive document
Ctrl + Super + X to cut selections to the inactive document

Applescript for copying the current line of text?

I'd like to create an applescript that will copy the entire line that the carat is currently on. After doing a fair amount of googling, however, I have come up empty. Any ideas?
(*
Save this as an application
Right click the application and select "Show Package Contents"
Add this to Info.plist between <dict> and </dict>
<key>LSBackgroundOnly</key>
<true/>
launch the application with spotlight (command space)
*)
tell application "System Events"
key code 123 using {command down, shift down}
key code 124 using {command down, shift down}
keystroke "c" using {command down}
end tell
Below is some code I wrote for Xcode 9 (I finally got it working as of updated 3-5-18). I wanted a feature that every text editor I've used in the past 25 years. A copy with no selection would copy the current line. The code figures out what paragraph (line) the caret is on and if there is any text selected. The same code can be modified to include Cut.
I execute this code using Keyboard Maestro. Add the below (3) actions. You must disable the "Execute Applescript" macro before executing it otherwise the Command+C that is sent from within the code will cause an infinite loop:
Disable Macro "the current macro"
Execute Applescript "paste the AppleScript code in the edit box"
Enable Macro "the current macro"
Also, enable Xcode 9 key bindings to have Command+L do a select line. Use the "Text" tab to see less actions.
I also add the following to the DefaultKeyBinding.dict file.
https://www.maketecheasier.com/fix-home-end-button-for-external-keyboard-mac/
{
/* Remap Home/End keys to be like Windows */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
/* page up/down and move the caret like Windows*/
"\UF72C" = "pageUp:";
"\UF72D" = "pageDown:";
/* Option Home/End keys Beginning/End of Document like Mac */
"~\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"~\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$~\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$~\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
/* Ctrl Home/End keys Beginning/End of Document like Mac */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
"$^\UF72B" = "moveToEndOfDocumentAndModifySelection:"; /* Shift + Ctrl + End */
}
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use application "Xcode-beta"
global appName
set appName to "Xcode-beta"
-- for some reason pressing command+C only works ever other time without this
--delay 0.1
tell application appName
activate
set theDocuments to every source document
-- exit if no source documents are found
if theDocuments is equal to {} then
-- copy command must go somewhere i.e. the user might have copied an Icon.
tell application "System Events" to keystroke "c" using {command down}
do shell script "logger -t 'AS DEBUG' " & "Applescript CopyCurrentLine - exit if no source documents are found"
return -- exit script
end if
-- Note:
-- window 1 is where source documents live
-- It sure would've been nice if window contained a reference to its source document but it doesn't
-- if window has been edited its' name ends with " — Edited" and it needs to be trimed off
set windowName to name of window 1
if windowName ends with " — Edited" then
set windowName to my trimText(windowName, " — Edited", "end")
end if
-- try to find the windows' current source document by matching window name to source document name
repeat with theDoc in theDocuments
set theDocName to name of theDoc
if theDocName is equal to windowName then
exit repeat -- found the document
else
set theDocName to "" -- didn't find the document
end if
end repeat
-- exit if the window is not a source document
if theDocName is equal to "" then
-- copy command must go somewhere i.e. the user might have copied an Icon.
tell application "System Events" to keystroke "c" using {command down}
do shell script "logger -t 'AS DEBUG' " & "Applescript CopyCurrentLine - exit if the window is not a source document"
return -- exit script
end if
--set theDoc to last source document
set docText to the text of theDoc
-- get location of selected text
set {startPos, endPos} to selected character range of theDoc
if (my isSelectedTextRangeEmpty(theDoc)) then
-- select current line
-- I set a keybinding in Xcode so Command+L would call the Command 'Select Line'
tell application "System Events" to keystroke "l" using {command down}
end if
-- copy the selection to the clipboard
set selectedText to my getSelectedText(theDoc, docText)
-- restore insertion point to original location
set selected character range of theDoc to {startPos, endPos}
set the clipboard to selectedText
end tell
on getSelectedText(theContainer, docText)
-- get the selected text
set {startPos, endPos} to selected character range of theContainer
if {endPos < startPos} then
return ""
else
return (text startPos thru endPos) in docText
end if
end getSelectedText
on isSelectedTextRangeEmpty(theContainer)
set selectedCharacterRange to selected character range of theContainer
set {startPos, endPos} to selectedCharacterRange
if {endPos < startPos} or ¬
(selectedCharacterRange is equal to {}) or ¬
(length of selectedCharacterRange is equal to 0) then
return true
else
return false
end if
end isSelectedTextRangeEmpty
on trimText(theText, theCharactersToTrim, theTrimDirection)
-- "beginning", "end", "both"
set theTrimLength to the length of the theCharactersToTrim
-- TRIM BEGINNING
if the theTrimDirection is in {"beginning", "both"} then
repeat while theText begins with the theCharactersToTrim
try
set theText to characters (theTrimLength + 1) thru -1 of theText as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the theTrimDirection is in {"end", "both"} then
repeat while theText ends with the theCharactersToTrim
try
set theText to characters 1 thru -(theTrimLength + 1) of theText as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return theText
end trimText

Resources