I'm trying to change font color in One Note trough an autohotkey - autohotkey

Im using this code in the autohotkey converter because I would like to press for example:
'ctrl + alt + r' to change the font color
SetTitleMatchMode, RegEx ; match window titles by regular expressions
#IfWinActive - OneNote$ ; ------ only in windows with title ending with "- OneNote"
^!p::Send, !hfca!hfc{Down 7}{Right 4}{Enter}
^!r::Send, !hfcm^{PgDn}!r255{Tab}5{Tab}0{Enter} ; red (255, 0, 0)
^!b::Send, !hfcm^{PgDn}!r0{Tab}5{Tab}255{Enter} ; blue (0, 0, 255)
^!a::Send, !hfca ; automatic color (i.e. reset font color to "none")
#IfWinActive ; ------ end of section restricted to specific windows
I executed this code trough the .exe file but nothing happened

Related

How to edit paths in Windows clipboard?

When pressing "Ctr+C" while selecting some files in the explorer, their paths are saved in the clipboard and when later pressing "Ctr+V" the files are pasted. For an AutoHotkey script I need to edit these paths in the clipboard, so the explorer pastes other files in the location of the "Ctr+V" press. So for example I want to select the file "A.txt" in "C:\Folder1" with "Ctr+C", then activate the AutoHotkey script to change the stored information in the clipboard of "A.txt" to the information about another file "B.txt", so when pressing "Ctr+V" in "C:\Folder2" the explorer copies "B.txt" instead of "A.txt".
But I have no idea how the paths of "Ctr+C" are exactly stored in the clipboard and I found no useful documentation. Different programms to access the content of the clipboard give one of the three results: 1) [Absolute nothing] 2) "C://A.txt" 3) "file:///C:/A.txt". But when editing the clipboard to "C://B.txt" or "file:///C:/B.txt" I got no reaction of the file explorer when using "Ctr+V".
So how are the paths of copied files exactly stored in the clipboard and with which programm I could edit them?
Edit: Following expamle to explain exactly what my goal is: Suppose I have a file "A.txt" in path 1, which I want to move to path 2 and another file "B.txt" in path 3, which I want to move to path 4. The normal procedure would be:
1) Copy "A.txt" with "Ctr+C" in path 1.
2) Paste "A.txt" with "Ctr+V" in path 2.
3) Copy "B.txt" with "Ctr+C" in path 3.
4) Paste "B.txt" with "Ctr+V" in path 4.
The goal of my AutoHotkey script is to allow the following alternative:
1) Copy "A.txt" with "Ctr+C+1" in path 1.
2) Copy "B.txt" with "Ctr+C+2" in path 2.
3) Paste "A.txt" with "Ctr+V+1" in path 1.
4) Paste "B.txt" wiht "Ctr+V+2" in path 2.
At first glance it might seem unnecessary, but when organising a lot of files in more complex system, it would be really convenient for me. Ideally, it should also work when I add "C.txt", "D.txt", ... to be saved in the third/fourth/... clipboard slot and even when instead of "A.txt" I want to store multiple files in one clipboard slot; later I also want to implement "Ctr+X+[n]" to cut files.
I experimented a lot and was able to save the different paths of the files from the clipboard to AutoHotkey variables. But now I have to load the paths, which are stored in the AutoHotkey variables back to the clipboard, so the corresponding files are pasted with the explorer.
So just for an example: My AutoHotkey script detects the keyboard input "Ctr+C+1" while I select A.txt in the file explorer, then sends the computer the shorcut "Ctr+C" to store the path of A.txt in the clipboard and finally saves this path as "C:/A.txt" in the AutoHotkey varibale "clip1". Then I select B.txt in the file explorer, press "Ctr+C+2", so the AutoHotkey script presses "Ctr+C" to get the file paths into the Windows clipboard and then saves ít as "C:/B.txt" in "clip2". Now I press "Ctr+V+1", so the AutoHotkey script should write the path from the variable "clip1" back in the Windows, then press "Ctr+V" to paste the file in the explorer. But the really problem is now, that it is not enough to just edit the Windows clipboard to "C:/A.txt". Then so the explorer doesnt react to the input "Ctr+V", for which he should paste the file. So, the Windows clipboard has to be edited in another format, like for example "#explorer_file:///C:/A.txt" (just a complete stupid guess, since I have no idea how it looks). I need to find this format, so my AutoHotkey script can edit the currently saved paths to another paths.
I hope that explains all confusion about this confusing problem.
I'd use something like this:
#NoEnv
#SingleInstance Force
; Create a GUI with checkboxes to save the path of the last copied files and
; copy/move selected items to another directory opened in explorer:
OnClipboardChange("files_copied")
return
files_copied(type){
global
If (type == 1) ; the Clipboard contains text or files copied
{
; https://autohotkey.com/board/topic/150291-detect-clipboard-contents-as-text-file-etc/#entry735751
If (DllCall("IsClipboardFormatAvailable", "uint", 15)) ; the Clipboard contains files
{
ToolTip, file(s) copied
Gui, destroy
Gui, Color, ControlColor, Black
Gui, Font, CDefault, Lucida Console
Gui, Add, Button, x30 y5 w100 h26 gCopy ,Copy
Gui, Add, Button, x230 y5 w100 h26 gMove ,Move
Gui, Add, CheckBox, x20 y50 vCh200 gCheckAll cYellow, Select All
Gui, Add, CheckBox, x20 y75 vCh201 gUnCheckAll cYellow, De-Select All
Loop, Parse, Clipboard, `n, `r
{
y_pos := 100 + (A_Index * 25)
Gui, Add, CheckBox, x20 y%y_pos% vCh%A_Index% cYellow, %A_LoopField%
I := A_Index ; number of copied files
}
Gui_height := 125+I*25
Gui, Show, x100 y5 w400 h%Gui_height%, Files copied ; comment out this line if you want to only show the Gui after pressing F1
Sleep 1000
ToolTip
}
}
}
; Press F1 to show the Gui if it's hidden
F1:: Gui, Show
; or If the command in the above function is commented out
; F1:: Gui, Show, x100 y5 w400 h%Gui_height%, Files copied
CheckAll:
Loop, %I%
GuiControl,, Ch%A_Index%, 1
GuiControl,, Ch200, 1
GuiControl,, Ch201, 0
return
UnCheckAll:
Loop, %I%
GuiControl,, Ch%A_Index%, 0
GuiControl,, Ch200, 0
GuiControl,, Ch201, 1
return
Copy:
Gui, submit, nohide
If !WinExist("ahk_class CabinetWClass") ; explorer
{
MsgBox, No explorer window exists
return
}
WinActivate, ahk_class CabinetWClass
WinWaitActive, ahk_class CabinetWClass, ,2
If (ErrorLevel)
{
MsgBox, explorer could not be activated
return
}
ExplorerPath := GetActiveExplorerPath()
Loop %I%
{
GuiControlGet, checked,, Ch%A_Index%, Value
If (checked = 1) ; if the control is checked
{
GuiControlGet, file,, Ch%A_Index%, Text
FileCopy, %file%, %ExplorerPath%\, 1 ; overwrite existing files
}
}
return
Move:
Gui, submit, nohide
If !WinExist("ahk_class CabinetWClass") ; explorer
{
MsgBox, No explorer window exists
return
}
WinActivate, ahk_class CabinetWClass
WinWaitActive, ahk_class CabinetWClass, ,2
If (ErrorLevel)
{
MsgBox, explorer could not be activated
return
}
ExplorerPath := GetActiveExplorerPath()
MsgBox, 262180, Move Files, Are you sure you want to move the selected files to`n`n%ExplorerPath%?
IfMsgBox No
return
New_Clipboard := ""
Loop %I%
{
GuiControlGet, checked,, Ch%A_Index%, Value
If (checked = 1) ; if the control is checked
{
GuiControlGet, file,, Ch%A_Index%, Text
FileMove, %file%, %ExplorerPath%\, 1 ; overwrite existing files
}
else
{
GuiControlGet, file,, Ch%A_Index%, Text
New_Clipboard .= file . "`n" ; concatenate the outputs
}
}
If (New_Clipboard = "")
Gui, destroy
else
ClipboardSetFiles(New_Clipboard, DropEffect := "Copy")
return
GuiClose:
Gui, Hide
return
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925
GetActiveExplorerPath()
{
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
{
return window.Document.Folder.Self.Path
}
}
}
}
; https://autohotkey.com/boards/viewtopic.php?p=63914#p63914
ClipboardSetFiles(FilesToSet, DropEffect := "Copy") {
; FilesToSet - list of fully qualified file pathes separated by "`n" or "`r`n"
; DropEffect - preferred drop effect, either "Copy", "Move" or "" (empty string)
Static TCS := A_IsUnicode ? 2 : 1 ; size of a TCHAR
Static PreferredDropEffect := DllCall("RegisterClipboardFormat", "Str", "Preferred DropEffect")
Static DropEffects := {1: 1, 2: 2, Copy: 1, Move: 2}
; Count files and total string length
TotalLength := 0
FileArray := []
Loop, Parse, FilesToSet, `n, `r
{
If (Length := StrLen(A_LoopField))
FileArray.Push({Path: A_LoopField, Len: Length + 1})
TotalLength += Length
}
FileCount := FileArray.Length()
If !(FileCount && TotalLength)
Return False
; Add files to the clipboard
If DllCall("OpenClipboard", "Ptr", A_ScriptHwnd) && DllCall("EmptyClipboard") {
; HDROP format
; 0x42 = GMEM_MOVEABLE (0x02) | GMEM_ZEROINIT (0x40)
hDrop := DllCall("GlobalAlloc", "UInt", 0x42, "UInt", 20 + (TotalLength + FileCount + 1) * TCS, "UPtr")
pDrop := DllCall("GlobalLock", "Ptr" , hDrop)
Offset := 20
NumPut(Offset, pDrop + 0, "UInt") ; DROPFILES.pFiles = offset of file list
NumPut(!!A_IsUnicode, pDrop + 16, "UInt") ; DROPFILES.fWide = 0 --> ANSI, fWide = 1 --> Unicode
For Each, File In FileArray
Offset += StrPut(File.Path, pDrop + Offset, File.Len) * TCS
DllCall("GlobalUnlock", "Ptr", hDrop)
DllCall("SetClipboardData","UInt", 0x0F, "UPtr", hDrop) ; 0x0F = CF_HDROP
; Preferred DropEffect format
If (DropEffect := DropEffects[DropEffect]) {
; Write Preferred DropEffect structure to clipboard to switch between copy/cut operations
; 0x42 = GMEM_MOVEABLE (0x02) | GMEM_ZEROINIT (0x40)
hMem := DllCall("GlobalAlloc", "UInt", 0x42, "UInt", 4, "UPtr")
pMem := DllCall("GlobalLock", "Ptr", hMem)
NumPut(DropEffect, pMem + 0, "UChar")
DllCall("GlobalUnlock", "Ptr", hMem)
DllCall("SetClipboardData", "UInt", PreferredDropEffect, "Ptr", hMem)
}
DllCall("CloseClipboard")
Return True
}
Return False
}

OneNote intercepts pen cursor before AHK?

Palm rejection is garbage on my laptop, so I disabled the HID touchscreen to make it so that only pen input registers. So, I used AHK to make a script that will scroll around the page after the user presses ALT, and disables scrolling upon the second ALT press.
It works great, except that in OneNote (the Win 10 app), pen cursor input is hijacked by OneNote. For example, if I make a ToolTip, %xPos% %yPos%, then it won't update while my pen cursor is hovering anywhere above the OneNote window. Anywhere outside this works fine.
How can I make AHK steal pen cursor input before OneNote can get it?
isTabletMode := 1
penScrollActive := 0
#MaxThreadsPerHotkey 2 ; Allows a second instance to modify penScrollActive while PenScroll is looping.
$Alt::
; Check if PC is in tablet mode.
; 1 --> Tablet, 0 --> Desktop
RegRead, isTabletMode, HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\ImmersiveShell,TabletMode
if(isTabletMode) {
if(penScrollActive) {
penScrollActive := 0 ; We are already scrolling, so turn it off.
}
else {
penScrollActive := 1 ; We are not scrolling yet, so turn on pen scrolling.
}
GoSub PenScroll
}
else ; If we aren't in tablet mode, then Alt should just send Alt
Send, {Alt}
return
PenScroll:
loop { ; For some reason, while() logic wasn't working, so this is a workaround. Breaks upon the conditional at bottom.
MouseGetPos, mouseX, mouseY
ToolTip, %mouseX% %mouseY% ; For debugging: Output what cursor pos registers as. (This isn't working in OneNote when using the pen input as a cursor (eg. hover) ).
Sleep, 20
MouseGetPos, mouseX_new, mouseY_new
if (mouseX_new - mouseX > 0) ; Horizontal scrolling
Send, {WheelLeft}
else if (mouseX_new - mouseX < 0)
Send, {WheelRight}
if (mouseY_new - mouseY > 0) ; Vertical scrolling
Send, {WheelUp}
else if (mouseY_new - mouseY < 0)
Send, {WheelDown}
if (penScrollActive = 0) ; Conditional to break out
break
}
return
; To Reload the script: Win+`
#`::Reload
Return
#If penScrollActive
LButton::Return
One thing you could maybe try is my AutoHotInterception library for AHK. You install a custom device driver, then you can hook into input events at the driver level, below the OS.
It supports "Absolute" (Graphics-tablet-like) mouse input
You want the "Subscription Mode" endpoints

Surrounding Clipboard with quotes in URL

Warning: I'm very new to this.
I'd like to make Google searches quicker by assigning a hotkey to search a text selection (in web browser) and surrounding that search with quotes (to get exact matches).
I've tried using bits of code I have found, but so far I can only search the selected text on Google, but don't know how to surround the selected text in quotes in the search.
^!d:: ;
prevClipboard := ClipboardAll
SendInput, ^c
ClipWait, 1
if !(ErrorLevel) {
Clipboard := RegExReplace(RegExReplace(Clipboard, "\r?\n"," "), "(^\s+|\s+$)")
If SubStr(ClipBoard,1,7)="http://"
Run, % Clipboard
else
Run, % "https://www.google.com/search?q=" Clipboard
}
Clipboard := prevClipboard
return
This simply opens a google search with the clipboard.
I cannot find out how to make it so "Clipboard" is searched instead of Clipboard.
Any suggestions? Thanks!
Run is a command and variables in commands have to be enclosed in percent signs.
To include an quote, specify two consecutive quotes twice:
Run, http://www.google.com/search?q=""%Clipboard%""
If you want to do a "Phase google search" from any Selected Text (And From Out Everywhere, on your Computer System.)
Then you can try this AHK Script.
you can [Select any Text] and then you can click the [F1] key from your Keyboard Device.
The Computer Find automatic out where it can do the Query Search (us 100x results) and what Browser it must use.
Example1.ahk
;#notrayicon
#SingleInstance force
GroupAdd, Browser, ahk_class Chrome_WidgetWin_1 ; Chrome or Iron
GroupAdd, Browser, ahk_class IEFrame ; Internet Explorer
GroupAdd, Browser, ahk_class MozillaWindowClass ; FireFox
GroupAdd, Browser, ahk_class ApplicationFrameWindow ; Edge
; here you can change the variable into exact search [
quote1 = "
; here you can change the variable into exact search ]
quote2 = "
; here you can change the variables intitle: - inurl: - inanchor: - allinurl: - allinanchor:
insearch = allintitle:
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
If WinActive("ahk_group Browser")
{
sendinput ^c ;copy the selected text to clipboard memory
sleep 150
sendinput ^t ;CTRL+t make a new tab + goto address bar - use CTRL+L for the active tab + goto address bar
sleep 150
texta = https://www.google.com/?gfe_rd=cr&gws_rd=cr#q=%insearch%%quote1%
textb = %clipboard%%quote2% ;selected text
textc = &lr=lang_us&hl=us&num=100 ; google parameters
clipboard=%texta%%textb%%textc%
sleep 150
sendinput ^v ; paste the selected text
sleep 250
send {enter}
clipboard=%textb%
} else {
sendinput ^c ;copy the selected text to clipboard memory
sleep 150
texta = https://www.google.com/?gfe_rd=cr&gws_rd=cr#q=%insearch%%quote1%%quote1%
textb = %clipboard%%quote2%%quote2%%quote2% ;selected text
textc = &lr=lang_us&hl=us&num=100 ; google parameters
clipboard=%texta%%textb%%textc%
run %clipboard%
clipboard=%textb%
}
return

Can't get clipboard printed to GUI to update on autohotkey

So I can't seem to get it to change, it's supposed to print out whatever I have copied to my clipboard onto the gui. but I can't seem to get it to update
b = 0
Gui, New, +Resize -MaximizeBox, Farming
Gui, Color, EEAA99
Gui +LastFound
WinSet, TransColor, EEAA99(True)
Gui, Farming:+AlwaysOnTop +Disabled -SysMenu +Owner
while(True)
{
new1 = %clipboard%
if(b == 0)
{
Gui, Farming:Add, Text, Vkek, Current copied: %new1%
Gui, Farming:Show, AutoSize Center
clips = %new1%
b = 1
}
if(%new1% <> %clips%)
{
b = 0
}
}
change if(%new1% <> %clips%) to if(new1 <> clips). You can read about comparing variables in the documentation here:
https://autohotkey.com/docs/Variables.htm#Expressions
Once that is fixed you are going to have another issue in that you will be trying to add a new text control to your gui with the same variable as an existing control (kek). Instead, you need to change the content of the text control using GuiControl command:
https://autohotkey.com/docs/commands/GuiControl.htm

Toggle HighContrast Theme - windows 10

I want to be able to toggle the HighContrast Theme in Windows 10, by pressing F1.
The shortcut for toggling the HighContrast Theme in Windows 10 is:
Left Alt + Left Shift + Print Screen
https://msdn.microsoft.com/en-us/library/hh923906.aspx
Here is my script:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Toggle HighContrast Theme: Alt + Shift + PrintScreen
F1::
Send !+{PrintScreen}
Return
You can apply the setting by manually running the .theme file. The problem is that it will open the Settings dialog. This script will run the high contrast 1 theme file, wait for the Settings dialog to open, then close it.
Edit: Added code to toggle between two themes
hc := false
hctheme := "C:\Windows\Resources\Ease of Access Themes\hc1.theme"
stdtheme := "C:\Windows\Resources\Themes\theme1.theme"
; your personalized theme may be in
; C:\Users\{user.name}\AppData\Local\Microsoft\Windows\Themes\Custom.theme
F1::
hc := !hc
if (hc)
run %hctheme%
else
run %stdtheme%
WinWait Settings
WinClose Settings
return
In testing this, it seems that the Alt+PrtScr keyboard combo is hooked too low in the OS to be overridden by AutoHotKey to add in the Shift modifier before it just goes with the default of taking a screenshot of the active window. (Looking around the AHK forums, this seems to be the consensus as well.)
I did manage to find some script suggestions here, of which this slight modification does work for me on Win10 Pro:
F1:: ;toggle high contrast
vSize := A_PtrSize=8?16:12
VarSetCapacity(HIGHCONTRAST, vSize, 0)
NumPut(vSize, &HIGHCONTRAST, 0, "UInt") ;cbSize
;SPI_GETHIGHCONTRAST := 0x42
DllCall("user32\SystemParametersInfo", UInt,0x42, UInt,vSize, Ptr,&HIGHCONTRAST, UInt,0)
vFlags := NumGet(&HIGHCONTRAST, 4, "UInt") ;dwFlags
;JEE_Progress(vFlags, 1000)
if (vFlags & 1) ;HCF_HIGHCONTRASTON := 0x1
vFlags -= 1
else
vFlags += 1
;JEE_Progress(vFlags, 1000)
VarSetCapacity(HIGHCONTRAST, vSize, 0)
NumPut(vSize, &HIGHCONTRAST, 0, "UInt") ;cbSize
NumPut(vFlags, &HIGHCONTRAST, 4, "UInt") ;dwFlags
;SPI_SETHIGHCONTRAST := 0x43
DllCall("user32\SystemParametersInfo", UInt,0x43, UInt,vSize, Ptr,&HIGHCONTRAST, UInt,0)
return
Use this:
F1::
Send {LAlt down}{LShift down}{PrintScreen}{LAlt Up}{LShift Up}
return
From official documentation:
Press use down like : {LWin down} {RWin down}
Release use up like : {LWin up} {RWin up}