Use Numpad for AHK while Mousekeys is activated Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hotkeyuser1234
Posts: 92
Joined: 07 Mar 2020, 12:27

Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 24 Jan 2021, 11:32

Dear community,

I like using both AHK and mousekeys. It seems like keys on the numpad are not recognized while Mousekeys is activated as also discussed here: https://autohotkey.com/board/topic/101198-autohotkey-along-side-windows-mouse-keys/.

I would be happy if you could provide me support for one of two resolution ideas:
1) Is there a way to still get the Numpad keys working while Mousekeys is on so that I could e.g. use

Code: Select all

PgDn & NumPgDn
for AHK?
2) Are you aware of an AHK script that imitates the behavior of Mousekeys? I found a few scripts including https://github.com/DarthBrento/MouseKeysPlusPlus/blob/master/MouseKeys%2B%2B.ahk but it does not seem to work.

Thank you very much in advance for your answer!
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Use Numpad for AHK while Mousekeys is activated

Post by mikeyww » 24 Jan 2021, 11:45

Here is MouseKeys. You can now add whatever you like.

Code: Select all

amount   := 3
mouseKey := {1: [-1,  1], 2: [ 0,  1], 3: [ 1,  1], 4: [-1,  0], 6: [ 1,  0], 7: [-1, -1], 8: [ 0, -1], 9: [ 1, -1]}
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad6::
Numpad7::
Numpad8::
Numpad9::MouseMove, amount * mouseKey[key := SubStr(A_ThisHotkey, 7)].1, amount * mouseKey[key].2,, R
hotkeyuser1234
Posts: 92
Joined: 07 Mar 2020, 12:27

Re: Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 24 Jan 2021, 12:07

Wow, this is awesome, thank you so much!

One thing which would make it even greater is acceleration over time like in the mousekeys program. A way how I could imagine it is e.g. pressing

Code: Select all

PgDn & NumPgDn 
to go down with usual speed and pressing NumPgDn twice (while holding PgDn) would double the speed. Is this possible somehow?

Thanks for your further help!
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Use Numpad for AHK while Mousekeys is activated  Topic is solved

Post by mikeyww » 24 Jan 2021, 13:05

Here is an adjustable accelerator.

Code: Select all

moveMin := 2, moveMax := 150, overSec := 5
F3::SoundBeep, (mouseKeysOn := !mouseKeysOn) ? 1500 : 1000, 30 ; F3 = Toggle MouseKeys
F4:: ; F4 = Exit
SoundBeep, 1000, 30
ExitApp

#If mouseKeysOn
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad6::
Numpad7::
Numpad8::
Numpad9::
start := A_TickCount
While GetKeyState(A_ThisHotkey, "P") { ; Accelerate while key is held
 amount := Min(moveMax, Round(moveMin + (A_TickCount - start) * (moveMax - moveMin) / overSec / 1000))
 move(SubStr(A_ThisHotkey, 7), amount)
}
Return

move(key, amount) {
 Static mouseKey := { 7: [-1, -1], 8: [ 0, -1], 9: [ 1, -1]
                    , 4: [-1,  0]             , 6: [ 1,  0]
                    , 1: [-1,  1], 2: [ 0,  1], 3: [ 1,  1]}
 MouseMove, amount * mouseKey[key].1, amount * mouseKey[key].2,, R
}
If you need to use something like PgDn as an auxiliary key, below is an example of how you can determine whether it is being held.

Code: Select all

PgDn::
Numpad4::
Numpad5::
num := GetKeyState("Numpad4", "P") || GetKeyState("Numpad5", "P")
aux := GetKeyState("PgDn", "P")
If num && aux
 Send Both `
Else Send %A_ThisHotkey% `
Return
This second way is trickier-- prone to getting stuck.
hotkeyuser1234
Posts: 92
Joined: 07 Mar 2020, 12:27

Re: Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 24 Jan 2021, 14:02

Perfect, thank you! This is so nice:) I'll now only complement it with left, right and double left click
hotkeyuser1234
Posts: 92
Joined: 07 Mar 2020, 12:27

Re: Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 28 Dec 2021, 05:39

Thanks so much again for your help. I have been using your script (see “Mousekey Original” below) for quite some time which allows me to navigate using the NumPad rather than the mouse when NumLock is active. I would like to adjust the functionality so that I can use the Home, End, PgUp and PgDn functionality. I adjusted the script so that holding CTRL at the same time would trigger each of these actions. I am unsure why my script (see “Mousekey adjusted”) does not work. Even the original mousekey functionality does not work anymore. I would really appreciate your help.
Thanks!

Mousekey Original:

Code: Select all

moveMin := 10, moveMax := 150, overSec := 5
Numpad1:: 
Numpad2::
Numpad3::
Numpad4::
Numpad6::
Numpad7::
Numpad8::
Numpad9::
start := A_TickCount
While GetKeyState(A_ThisHotkey, "P") { ; Accelerate while key is held
 amount := Min(moveMax, Round(moveMin + (A_TickCount - start) * (moveMax - moveMin) / overSec / 1000))
 move(SubStr(A_ThisHotkey, 7), amount)
}
Return

move(key, amount) {
 Static mouseKey := { 7: [-1, -1], 8: [ 0, -1], 9: [ 1, -1]
                    , 4: [-1,  0]             , 6: [ 1,  0]
                    , 1: [-1,  1], 2: [ 0,  1], 3: [ 1,  1]}
 MouseMove, amount * mouseKey[key].1, amount * mouseKey[key].2,, R
}
Mousekey adjusted:

Code: Select all

moveMin := 10, moveMax := 150, overSec := 5
Numpad1:: 
	if GetKeyState("^", "P")
	Send End
	Return
Numpad2::
Numpad3::
	if GetKeyState("^", "P")
	Send PgDn
	Return
Numpad4::
Numpad6::
Numpad7::
	if GetKeyState("^", "P")
	Send Home
	Return
Numpad8::
Numpad9::
	if GetKeyState("^", "P")
	Send PgUp
	Return
start := A_TickCount
While GetKeyState(A_ThisHotkey, "P") { ; Accelerate while key is held
 amount := Min(moveMax, Round(moveMin + (A_TickCount - start) * (moveMax - moveMin) / overSec / 1000))
 move(SubStr(A_ThisHotkey, 7), amount)
}
Return

move(key, amount) {
 Static mouseKey := { 7: [-1, -1], 8: [ 0, -1], 9: [ 1, -1]
                    , 4: [-1,  0]             , 6: [ 1,  0]
                    , 1: [-1,  1], 2: [ 0,  1], 3: [ 1,  1]}
 MouseMove, amount * mouseKey[key].1, amount * mouseKey[key].2,, R
}
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Use Numpad for AHK while Mousekeys is activated

Post by mikeyww » 28 Dec 2021, 07:46

Code: Select all

moveMin  := 2, moveMax := 150, overSec := 5
mouseKey := { 7: [-1, -1], 8: [ 0, -1], 9: [ 1, -1]
            , 4: [-1,  0]             , 6: [ 1,  0]
            , 1: [-1,  1], 2: [ 0,  1], 3: [ 1,  1]}
F3::SoundBeep, (mouseKeysOn := !mouseKeysOn) ? 1500 : 1000, 30 ; F3 = Toggle MouseKeys

#If mouseKeysOn
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad6::
Numpad7::
Numpad8::
Numpad9::
^Home::
^End::
^PgUp::
^PgDn::
start := A_TickCount                                           ; Mark the starting time
If !hk := {Home: 4, End: 6, PgUp: 8, PgDn: 2}[key := SubStr(A_ThisHotkey, 2)]
 key := A_ThisHotkey, hk := SubStr(key, 0)                     ; The Numpad number
While GetKeyState(key, "P") {                                  ; Accelerate while key is held
 amount := Min(moveMax, Round(moveMin + (A_TickCount - start) * (moveMax - moveMin) / overSec / 1000))
 MouseMove, amount * mouseKey[hk].1, amount * mouseKey[hk].2,, R
}
Return
#If
hotkeyuser1234
Posts: 92
Joined: 07 Mar 2020, 12:27

Re: Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 28 Dec 2021, 12:12

Thank you very much for your help! Unfortunately, when placing your code in my whole script, mousekeys do not seem to work anymore, both when holding CTRL and without holding it while NumLock is activated. This is my whole script:

Code: Select all

;;;;;;;;;;;;;IMPORTANT INFORMATION;;;;;;;;;;;;;;;;;;;;;;;;
;https://www.autohotkey.com/docs/KeyList.htm
; Autostart by creating shortcut to this folder: C:\Users\Alexa\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
;;;;;;;;;;; AUTO EXECUTE ON STARTUP;;;;;;;;;;;;;;;;;;;;;;;
Run Hotkey Help.ahk
;;;;;;;;;;;;;;;;FREE SHORTCUTS THAT CAN BE ASSIGNED;;;;;;;;;;;;;;;;;
;STRG + number, e.g. STRG+1/2 etc => But are needed in Chrome for navigating to certain tabs
;STRG + Shift + number>3
;;;;;;;;;;;;;;;;;;;;;; Start of mouse keys ;;;;;;;;;;;;;;;;;;;
; It is important that this is also at the beginning before any other return since it is otherwise not activated. Alternatively, it would need to be saved in another file 
; If NumLock is OFF but Shift is pressed, the system temporarily releases Shift and acts as though NumLock is ON.
moveMin  := 2, moveMax := 150, overSec := 5
mouseKey := { 7: [-1, -1], 8: [ 0, -1], 9: [ 1, -1]
            , 4: [-1,  0]             , 6: [ 1,  0]
            , 1: [-1,  1], 2: [ 0,  1], 3: [ 1,  1]}
F3::SoundBeep, (mouseKeysOn := !mouseKeysOn) ? 1500 : 1000, 30 ; F3 = Toggle MouseKeys

#If mouseKeysOn
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad6::
Numpad7::
Numpad8::
Numpad9::
^Home::
^End::
^PgUp::
^PgDn::
start := A_TickCount                                           ; Mark the starting time
If !hk := {Home: 4, End: 6, PgUp: 8, PgDn: 2}[key := SubStr(A_ThisHotkey, 2)]
 key := A_ThisHotkey, hk := SubStr(key, 0)                     ; The Numpad number
While GetKeyState(key, "P") {                                  ; Accelerate while key is held
 amount := Min(moveMax, Round(moveMin + (A_TickCount - start) * (moveMax - moveMin) / overSec / 1000))
 MouseMove, amount * mouseKey[hk].1, amount * mouseKey[hk].2,, R
}
Return

Numpad5::Click, left ; 5 on Numpad while NumLock is on: Left click
Return

Numpad0:: Click, 2 ; Double click:
NumpadDot:: Click, right
Return

^PgDn:: Click, down ; STRG+PgDn: Click and hold
Return
^PgUp:: Click, up ; STRG+PgDn: Release
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END OF MOUSEKEYS;;;;;;;;;;;;;;;;;;;;;;;;;
;*************************************************************
; The block below is to be placed in Auto-execute section of your ahk-file (at the very begining of the script).
;*************************************************************
HotkeysQuantity := 2  ; The number of hotkeys that are allowed to be fired within MinTimeInterval.
MinTimeInterval := 3000  ; In miliseconds
TimeStamps := []
Loop, % HotkeysQuantity
	TimeStamps.Push(0)
;*************************************************************

return 

TimeToWaitToolTip:
if ((TimeToWait := (MinTimeInterval - A_TickCount + TimeStamps[HotkeysQuantity])) > 0)
{   MouseGetPos, xtt, ytt
    ToolTip, % "Wait for " . Format("{:.1f}", TimeToWait//100/10) . " seconds", % xtt+40, % ytt-40, WaitToolTip
}
else {
    SetTimer, TimeToWaitToolTip, Off
    ToolTip, , , , WaitToolTip
}
return

FinishRoutine:
TimeStamps.InsertAt(1, A_TickCount)
TimeStamps.Pop()
SetTimer, TimeToWaitToolTip, 100
return

HCheck() {
	global
	return (A_TickCount - TimeStamps[HotkeysQuantity] > MinTimeInterval)
}

;;;;;;;;;;;;;;;;;;;;; BEGINNING OF NUMPAD KEYS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; All of the following shortcuts are on the Numpad and only work while NumLock is off (no light is on on the keyboard)

~^NumpadIns Up:: ;Right clicks were caret is, i.e. where writing in Word and not where mouse is; STRG Numpad 0
Sleep, 150
Send {AppsKey}
Return

NumpadIns:: ;0 on Numpad: Rightclick
if HCheck(){
	Click, right
}gosub, FinishRoutine
Return

NumPadEnd:: ; 1 on Numpad: Open WhatsApp
if HCheck(){
	Run %browser% "https://web.whatsapp.com/"
}gosub, FinishRoutine
Return

NumpadDown:: ;Copy full link to DOI and open in Sci-hub with 2 on Numpad
Clipboard  := ""
send ^c
ClipWait,2
Send {Ctrl up}
ClipCopy:=Clipboard
url:=GetURL(Clipboard)
If(StrLen(url)<1){ 
	url:=ClipCopy
}
Run, %browser% "https://sci-hub.se/"%url%
Return

NumpadPgDn:: ;3 on Numpad: Open (the selected word) in FreeCollocation Dictionary
Clipboard  := ""
send ^c
ClipWait,2
Searchstring:=StrReplace(Clipboard," ","%20")
Run, %browser% "http://www.freecollocation.com/search?word="%Searchstring%
Return

NumpadLeft:: ; 4: Thesaurus
Clipboard  := ""
send ^c
ClipWait,2
Send {Ctrl up}
Searchstring:=StrReplace(Clipboard," ","%20")
Run, %browser% "https://www.thesaurus.com/browse/"%Searchstring%
Return

NumpadClear:: ;Linguee with 5 on NumPad
Clipboard  := ""
send ^c
ClipWait,2
Send {Ctrl up}
Searchstring:=StrReplace(Clipboard," ","%20")
Run, %browser% "https://www.linguee.de/deutsch-englisch/search?source=auto&query="%Searchstring%
Return

; Search Person by name on Linkedin with 6 on Numpad
NumpadRight:: 
send ^c
ClipWait,2
Clipboard := StrReplace(Clipboard, " ", "%20")
Run, %browser% "https://www.linkedin.com/search/results/people/?keywords="%Clipboard%
return

NumpadHome:: ; Search on Google Scholar with 7 on NumPad
Clipboard  := ""
send ^c
ClipWait,2
Send {Ctrl up}
Searchstring:=StrReplace(Clipboard," ","%20")
; Removing blanks
Searchstring:=StrReplace(Searchstring, "`t")
; Removing tabs
Searchstring:=StrReplace(Searchstring, "%20&%20","%20%")
Searchstring:=StrReplace(Searchstring, "%20&%20","%20%")
Searchstring:=StrReplace(Searchstring, "%20&%20","%20%")
; replace two spaces after each other
Searchstring:=StrReplace(Searchstring, "&")
; replaces & since this does not seem to work with Google Scholar
Run, %browser% "https://scholar.google.com/scholar?hl=en&q="%Searchstring%
Return

NumpadUp:: ; 8 on NumPad; searches for the currently selected term on Google or opens the currently selected file ;or link 
WinGetClass, winClass, % "ahk_id" hWnd := WinExist("A")
If !(winClass ~= "Progman|WorkerW|(Cabinet|Explore)WClass") {
 Clipboard =
 Send ^c
 ClipWait, 1
 If ErrorLevel {
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
  Return
 } Else 
            url := Instr(Clipboard, "://") ? Trim(Clipboard)
            : "https://www.google.com/search?q=" StrReplace(Trim(Clipboard), " ", "%20")
} Else url := "file:///" Explorer_GetSelection().1
Searchstring:=StrReplace(url," ","%20")
Run, `"%Searchstring%`"
; TODO specify second preference according to file path:
file := Explorer_GetSelection().1
SplitPath, file,,, ext
Switch ext {
 Case "ahk": MsgBox, This is an AHK file.
 Case "txt": MsgBox, This is a text file.
}
Send {Ctrl up}
Return

Explorer_GetSelection() {
 ; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256
 WinGetClass, winClass, % "ahk_id" hWnd := WinExist("A")
 If !(winClass ~= "Progman|WorkerW|(Cabinet|Explore)WClass")
  Return
 shellWindows := ComObjCreate("Shell.Application").Windows, sel := []
 If !(winClass ~= "Progman|WorkerW") {
  For window in shellWindows
   If (window.HWND && hWnd = window.HWND && shellFolderView := window.Document)
    Break
 } Else shellFolderView := shellWindows.FindWindowSW(0, 0, 8, 0, SWFO_NEEDDISPATCH := 1).Document
 For item in shellFolderView.SelectedItems
  sel.Push(item.Path)
 Return sel
}

NumpadPgUp:: ;9; pastes without line breaks and formats; 
^!3::
NewString := RegExReplace(Clipboard,"\s+"," ")
Clipboard := NewString 
Send ^v
Send {Ctrl up}
Return

;Enter on NumPad
;NumpadEnter:: ;open the AHK script in NotePad
myPath := "C:\Users\Alexa\OneDrive - tum.de\Divers\Sonstiges\Efficiency & Shortcuts\hotkeys-private_v2.ahk"
SplitPath, myPath,,,,fName 
Run,% "notepad.exe " . myPath
If WinExist(fName)
    WinActivate 
Return

;Enter on NumPad
NumpadEnter:: ;Search for text to find doi
Send ^c
ClipWait, 1
Searchstring:= RegExReplace(Clipboard,"\s+"," ")
Searchstring:=StrReplace(Searchstring," ","%20")
Searchstring:=StrReplace(Searchstring, "&")
Searchstring:=StrReplace(Searchstring, "%20&%20","%20%")
Searchstring:=StrReplace(Searchstring, "`t")
Run, %browser% "https://search.crossref.org/?from_ui=&q="%Searchstring%
Exit

NumpadAdd:: ;Timer for selected number of minutes 
send ^c
Send {Ctrl up}
ClipWait,2
Run, "C:\Users\Alexa\OneDrive - tum.de\Divers\Sonstiges\Efficiency & Shortcuts\timer.ahk" %Clipboard%
return

NumPadSub:: ;-/minus on NumPad: goes back 10 units in video playing in different window 
SetKeyDelay 30,50
Send, {ALT DOWN}{TAB}{ALT UP}
Send, {Left 10} ; changing 10 or removing completely to {Left} would change units going back
SetKeyDelay 30,50
Send, {ALT DOWN}{TAB}{ALT UP}
Return

NumPadDel:: ;Collins Collocation Dictionary
Clipboard  := ""
send ^c
Send {Ctrl up}
ClipWait,2
Run, %browser% "https://www.macmillandictionary.com/collocations/british/"%Clipboard% ; american instead british possible
Return

NumpadMult:: ;Copies the currently selected content and afterwards the current URL (works in Chrome and Firefox)
; Does not seem to work fully
keywait, %A_ThisHotKey%
Clipboard := ""
send, ^c
Clipwait,1 ; Waits until the clipboard contains data and 1 second at most
sleep 500
Send, !d ; focus on url
clipboard := "" 	; Start off empty to allow ClipWait to detect when the text has arrived.
Send, ^c
Clipwait ; Waits until the clipboard contains data.
return

NumpadDiv:: ;Connect with Bluetooth headphones
;see https://www.autohotkey.com/boards/viewtopic.php?p=366804#p366804
deviceName := "LE_WH-1000XM3"
; Alternative: "AirPods Pro von Alexander"
DllCall("LoadLibrary", "str", "Bthprops.cpl", "ptr")
toggle := toggleOn := 1
VarSetCapacity(BLUETOOTH_DEVICE_SEARCH_PARAMS, 24+A_PtrSize*2, 0)
NumPut(24+A_PtrSize*2, BLUETOOTH_DEVICE_SEARCH_PARAMS, 0, "uint")
NumPut(1, BLUETOOTH_DEVICE_SEARCH_PARAMS, 8, "uint")   ; fReturnAuthenticated
VarSetCapacity(BLUETOOTH_DEVICE_INFO, 560, 0)
NumPut(560, BLUETOOTH_DEVICE_INFO, 0, "uint")
loop
{
   If (A_Index = 1)
   {
      foundedDevice := DllCall("Bthprops.cpl\BluetoothFindFirstDevice", "ptr", &BLUETOOTH_DEVICE_SEARCH_PARAMS, "ptr", &BLUETOOTH_DEVICE_INFO)
      if !foundedDevice
      {
         msgbox no bluetooth devices
         return
      }
   }
   else
   {
      if !DllCall("Bthprops.cpl\BluetoothFindNextDevice", "ptr", foundedDevice, "ptr", &BLUETOOTH_DEVICE_INFO)
      {
         msgbox no found
         break
      }
   }
   if (StrGet(&BLUETOOTH_DEVICE_INFO+64) = deviceName)
   {
      VarSetCapacity(Handsfree, 16)
      DllCall("ole32\CLSIDFromString", "wstr", "{0000111e-0000-1000-8000-00805f9b34fb}", "ptr", &Handsfree)   ; https://www.bluetooth.com/specifications/assigned-numbers/service-discovery/
      VarSetCapacity(AudioSink, 16)
      DllCall("ole32\CLSIDFromString", "wstr", "{0000110b-0000-1000-8000-00805f9b34fb}", "ptr", &AudioSink)
      loop
      {
         hr := DllCall("Bthprops.cpl\BluetoothSetServiceState", "ptr", 0, "ptr", &BLUETOOTH_DEVICE_INFO, "ptr", &Handsfree, "int", toggle)   ; voice
         if (hr = 0)
         {
            if (toggle = toggleOn)
               break
            toggle := !toggle
         }
         if (hr = 87)
            toggle := !toggle
      }
      loop
      {
         hr := DllCall("Bthprops.cpl\BluetoothSetServiceState", "ptr", 0, "ptr", &BLUETOOTH_DEVICE_INFO, "ptr", &AudioSink, "int", toggle)   ; music
         if (hr = 0)
         {
            if (toggle = toggleOn)
               break 2
            toggle := !toggle
         }
         if (hr = 87)
            toggle := !toggle
      }
   }
}
DllCall("Bthprops.cpl\BluetoothFindDeviceClose", "ptr", foundedDevice)
;msgbox done
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; End of script for connecting AirPods & END NUMPAD ;;;;;;;;;;;;;;;;;TEST;;;;;;;;;;;;;;;;;

;;;;;;;;;;; OWN ABBREVIATIONS;;;;;;;;;;;;;;;;;;;;;;;;;;
:oT:a@::[email protected]
:oT:c@::[email protected]
::a@@::[email protected] ; When form does not support enter, just type two @ and it will be replaced
:oT:t@::[email protected]
:cT:t@::[email protected]
:oT:g@::[email protected]
:oT:g2@::[email protected]
::g2@@::[email protected]
::ca@@::[email protected]
:oT:0@::017695815231
:oT:4@::4917695815231
:o:e@:::-*
:o:e1@::<3
::tu@::thank you
::thx::thanks
:o:V@::Vielen Dank im Voraus für Ihre Antwort
;::Mfg@::Mit freundlichen Grüßen
:X:Mfg@::SendInput, Mit freundlichen Gr{Alt Down}{Numpad0}{Numpad2}{Numpad5}{Numpad2}{Alt Up}{Alt Down}{Numpad2}{Numpad2}{Numpad5}{Alt Up}en
::BG@::Beste Grüße
::LG@::Liebe Grüße
::AF@::Alexander Farr
::Al@::Alexander
::DE64@::DE64 1203 0000 1051 9764 94
::BIC@::BYLADEM1001
::z@::https://tum-conf.zoom.us/j/8416984575?pwd=akFPbllVWE52NHBHbEIxeXNmWWdudz09
::zw@::Zwillingstraße 4, 80807 ;TODO make "ß" work
::su@::2 Summerfield, Cambridge CB3 9HE, UK
::21@::21.07.1998
::21/@::21/07/1998
::pics@::https://www.google.de/search?q=castle (site:focastock.com OR site:pexels.com OR site:allthefreestock.com OR site:unsplash.com OR site:startupstockphotos.com OR site:jaymantri.com OR site:moveast.me OR site:travelcoffeebook.com OR site:designerspics.com OR site:deathtothestockphoto.com OR site:foodiesfeed.com OR site:mazwai.com OR site:jeshoots.com OR site:superfamous.com OR site:pixabay.com OR site:picography.co OR site:magdeleine.co OR site:littlevisuals.co OR site:splitshire.com OR site:picjumbo.com OR site:lifeofpix.com OR site:gratisography.com OR site:getrefe.com OR site:nilssonlee.se OR site:thepatternlibrary.com OR site:publicdomainarchive.com OR site:isorepublic.com OR site:stokpic.com OR site:kaboompics.com OR site:bucketlistly.blog%2Fphotos OR site:freedigitalphotos.net OR site:morguefile.com OR site:publicdomainpictures.net OR site:stockvault.net OR site:imagefree.com OR site:rgbstock.com OR site:freeimages.com OR site:freerangestock.com OR site:stocksnap.io OR site:freenaturestock.com)&tbm=isch&tbs=isz:l

;;;;;;;;;;;;;;;;;;;;;;; MAPPING MISSING KEYS;;;;;;;;;;;;;;;;;;;; 
Capslock & Left::Send {Home}
return

Capslock & Right::Send {End}
return

;NumpadRight & Left::
Send +{Home}
return

;Left Alt + Shift + Left key is like FN+Left key, i.e. it selects everything in the row to the left of the cursor
;Capslock & Up::; would be good alternative key for this
<+<!Left::
Send +{Home}
return

<+<!Right:: ;Left Alt + Shift + Right key is like FN+Right key, i.e. it selects everything in the row to the right of the cursor
Send +{End}
return

^,::Send <
^.::Send >

^#v:: ; Paste without formatting (CTRL + Windows + V)
Clipboard := Clipboard
Send ^v
Return

^!c:: ; Second clipboard (CTRL + Alt + C/V)
Clipboard_temp := clipboardall
Clipboard := ""
Send ^c
Clipwait
Clipboard_2 := clipboardall
Clipboard := clipboard_temp
Return

^!v:: ;use two clipboards with STRG+ALT+C
Clipboard_temp := clipboardall
Clipboard := clipboard_2
Send ^v
Sleep 300
Clipboard := clipboard_temp
Return

;^#::;  in "Hotkey Help.ahk" file to restart this file

F5::Media_Play_Pause
F6::Media_Stop
F7::Media_Prev
F8::Media_Next
F9::Send {Volume_Down}
F10::Send {Volume_Up}
;Send {Volume_Up 3} would change it by three units
;SoundSet +10 ; would be alternative option
;There is also {Volume_Mute}

^+2:: ; Send current date: CONTROL+Shift+1
SendInput %A_DD%.%A_MM%.%A_YYYY% ; send current date; MMMM instead MM would be e.g. "March" instead of "03"
Return

^+1:: ;Puts the current windows on 80% width and opens notepad on the right of window: CONTROL+Shift+1
DetectHiddenWindows,on
SetWinDelay,0
Keywait,F1
WinGetPos,,,,H,AHK_class Shell_TrayWnd
WinGet,ID,ID,A
WinGet,Size,MinMax,A
If Size = 1
WinRestore,A
WinMove,A,,-8,-8,% A_ScreenWidth - ((A_ScreenWidth * 20) / 100),% 16 + A_ScreenHeight - H
WinGetPos,X,Y,W,H,A
Run,C:\Windows\System32\notepad.exe,,Hide,PID
WinWait,ahk_pid %PID%
WinMove,ahk_pid %PID%,,% A_ScreenWidth,% Y + 2,% A_ScreenWidth - W + 28,% H + 2
WinShow,ahk_pid %PID%
; WinMove,ahk_pid %PID%,,% W - 21,% Y + 2,% A_ScreenWidth - W + 28,% H + 2
;-------- Remove this part if you don't want the animation and uncomment the line above
M := A_ScreenWidth
Loop
{
M -= 100
If (M < W - 21)
Break
WinMove,ahk_pid %PID%,,% M
Sleep,10
}

^+3:: 
Loop, 0xFF
{
	Key := Format("VK{:02X}",A_Index)
	IF GetKeyState(Key)
		Send, {%Key% Up}
}
Return

^#!w:: ;Select the text for word counting, press CTRL+WIN+ALT+W, then pop up with the number of words in a MsgBox.
  OldClipboard := ClipboardAll
  Clipboard = ;clears the Clipboard
  Send, ^c
  ClipWait 0 ;pause for Clipboard data
  If ErrorLevel
  {
    MsgBox, No text selected!
  }
  RegExReplace(Clipboard, ".*?[a-zA-Z-(']+" ,
        , OutputVarCount, -1, 1) 
  MsgBox, %OutputVarCount% words!
  Clipboard := OldClipboard
Return
; ----------------------
WinActivate,ahk_pid %PID%
WinWaitClose,ahk_pid %PID%
WinMaximize,ahk_id %ID%
Return

;Use keyboard for arrows:
Capslock & j::Send {Left}
Capslock & i::Send {Up}
Capslock & k::Send {Down}
Capslock & l::Send {Right}

;Align elements in PowerPoint by CTRL+Shift+l/r/u/d keys:
#IfWinActive, ahk_exe POWERPNT.EXE
^!l::Send, !jdaal
^!r::Send, !jdaar
^!u::Send, !jdaat
^!d::Send, !jdaab

;^!right::
;ppt := ComObjActive("PowerPoint.Application")
;ppt.ActiveWindow.Selection.ShapeRange.Align(2, 0)
;Return

;^!left::
;ppt := ComObjActive("PowerPoint.Application")
;ppt.ActiveWindow.Selection.ShapeRange.Align(0, 0)
;Return

;;;;;;;;;;;;;;;;;;;;;;Change speaker;;;;;;;;;;;;;;;;;;,
^!1:: ;Select first speaker device with CTRL (^) ALT (!) 1
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down}
    ControlClick,&Set Default
    ControlClick,OK
    return
^!2:: ;Select second speaker device
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down 2}
    ControlClick,&Set Default
    ControlClick,OK
    return

;I would disable any devices that you won't be using, that way you will only have 2. If you want more (for other ;devices) just follow that pattern like this
;Hotkey ::

;   Run,mmsys.cpl

   WinWait,Sound

  ControlSend,SysListView321,{Down 3 (or whatever # you need it to be)}

  ControlClick,&Set Default
  ControlClick,OK
;  return

;;;;;;;;;;;;;;;;;;;;;;;;;Support functions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;Extract URL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GetURL(str){ ;Extract URL from String that Contains other Words
	result	:=	"" ;result to be returned
	
	; Parse through the string
	; Separate by spaces
	Loop, Parse, str, % A_Space
	{
		; Use RegEx to match anything that starts with an http://, https://, or www.
		If RegExMatch(A_LoopField, "i)^(http(s|)\:|www\.).*$")	;^(|http(|s)://)www\..*$
			; If match is made, append to result and add a comma
			; Result will return a comma separated value list (CSV) for easy parsing
			result	.=	((result = "") ? "" : ",") A_LoopField
	}	
	return result
}
;;;;;;;;;;;;;;;;;;;;;;;;;NOT FULLY WORKING;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;SetTimer, ResetCount, 1000 ;So that it will only do "it" once a second
;NumpadDown & LButton:: ; Open pressed Link on Scihub with Alt and left mouse click 
;Send {Rbutton}{up 3}{Enter}
;Run, %browser% "https://sci-hub.se/"%clipboard%
;Return 
;ResetCount:
;count = 0
;;;;;;;;;;;;;;;;;;;;SAVING NICE FEATURES;;;;;;;;;;;;;;;;;;;;;;;;;;
; Sound Beep
;SoundBeep, 1500, 30
; SmartGUI Creator for SciTE seems to be usable for creating GUIs
;;;;;;;;;;Shows a button
;Gui, Color, silver
;Gui, Add, Button, x145 y172 w180 h30 , Copy
;Gui, Show, x222 y304 h296 w468, New GUI Window
;Return

;NumpadPgDn:: ; Replaces current tab when current program is Chrome 
Clipboard  := ""
send ^c
ClipWait,2
IF !WinActive("ahk_exe %browser%")
	Run, %browser% "http://www.freecollocation.com/search?word="%Clipboard%
Else
{ ;open the website in the current tab
	SetKeyDelay, 200
	Send, ^l^a
	SendInput, http://www.freecollocation.com/search?word=%Clipboard%
	Send, {Return}
}
Return
;;;;;Search highlighted word among LinkedIn persons
;NumpadEnd::
send ^c
ClipWait,2
Clipboard := StrReplace(Clipboard, " ", "%20")
Run, %browser% "https://www.linkedin.com/search/results/people/?keywords="%Clipboard%
return

;;;;Open LinkedIn homepage
;NumpadDown::Run %browser% "https://www.linkedin.com"

;;;;;;Search highlighted word in Crunchbase
;NumpadPgDn::
;send ^c
;ClipWait,2
Clipboard := StrReplace(Clipboard, " ", "%20")
Run, %browser% "https://www.crunchbase.com/textsearch?q="%Clipboard%
return

;;;;;;;Open Crunchbase homepage
;NumpadLeft::Run %browser% "https://www.crunchbase.com/"

;;; Open GMail
;NumpadClear::Run %browser% "https://mail.google.com/mail/u/0/?ogbl#inbox"

;;; Copy text and open grammarly
Send ^c
Send {Ctrl up}
Run, https://app.grammarly.com
Return
;;;;;;;;;;;Zoom Notion pages:
;Open Zoom pages
Run, "notion://www.notion.so/8431ba54fed4455fb925c095052babc6?v=a8270ed7b512480392382668a54dd1d9"
return
;;;;;;;;;;;;;;;;USING DIFFERENT COMPUTERS;;;;;;;;;;;;;;;;;
if (A_ComputerName = "Computer") {
    FileRead, Script, %A_ScriptFullPath%
}
If (A_ComputerName = "Laptop") {
    FileRead, Script, %A_ScriptFullPath%
}
;;;;;;;;;;;;;;;;;;FREE SHORTCUTS
; ^<a; CTRL & Alt & a; did not work for date


browser:="C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
;C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe
I would really appreciate your help! Thank you!
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Use Numpad for AHK while Mousekeys is activated

Post by mikeyww » 28 Dec 2021, 12:18

See if my script works by itself first.
hotkeyuser1234
Posts: 92
Joined: 07 Mar 2020, 12:27

Re: Use Numpad for AHK while Mousekeys is activated

Post by hotkeyuser1234 » 28 Dec 2021, 16:44

I just tested it alone and it did not work (both when NumLock is on and off and when pressing CTRL or not). Is some part of the script missing? At the end of the code, there is:

Code: Select all

#If
. Maybe you forgot something?

Thank you very much in advance for your ongoing help!
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Use Numpad for AHK while Mousekeys is activated

Post by mikeyww » 29 Dec 2021, 06:53

So you closed your script, ran my script, pressed F3, and then held Ctrl+Home?
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Use Numpad for AHK while Mousekeys is activated

Post by boiler » 29 Dec 2021, 07:02

hotkeyuser1234 wrote: At the end of the code, there is:

Code: Select all

#If
. Maybe you forgot something?
Per the #If documentation:
To turn off context sensitivity, specify #If or any #IfWin directive but omit all the parameters. For example:

Code: Select all

#If
That would affect any hotkeys you might add below it.

If you don’t understand something, the first step should be to read the documentation about it.
Post Reply

Return to “Ask for Help (v1)”