Advertisement
coffeeAnon

Automatically switch to kana input

Jan 22nd, 2020
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.      AutoKanaInput.ahk
  3.     requires: autohotkey (obviously)
  4.             windows since windows messages are used
  5.                    to detect the input language
  6.             the image linked below
  7. _____________________________________________________________________________________________________________________
  8.  
  9.     The purpose of this script is to automatically force the windows input method to kana whenever japanese is
  10.     selected as the input language.
  11.    
  12.         General Usage
  13.     For this script to work correctly, you will have to change your input language to japanese via the default
  14.     hotkey combination, Shift+Alt. (this can of course be changed by minimally tweaking this script)
  15.     You could also try to modify the script to automatically detect the change to japanese, completely
  16.     independent of a hotkey by putting the part under ~+Alt:: into some kind of loop, but that sounds boring.
  17.    
  18.                               !! You will also need this image: !!
  19.             files.catbox.moe/a2ozv3.png | http://www.mediafire.com/view/lj6t9q586y4ip85/NEEDLE.png
  20.                   !! called NEEDLE.png to be located in the same folder as the script. !!
  21.                         in case both of these links stop working, pray to your
  22.                             diety of choosing and consult the limitiations
  23.                                         section below
  24.    
  25.                             ----------------------------------------
  26.  
  27.         Functionality
  28.     Because windows message documentation is absolute dogshit, this script searches for the provided image on
  29.     screen to check if the current input method is alphanumeric and if that is the case, sends the hotkey to
  30.     switch between kana and alphanumeric input (by default, Shift+Caps).
  31.     This behaviour can be suspended/reenabled by pressing the switch hotkey yourself.
  32.     Please note that if you suspend the auto switching, change your input to another language and switch
  33.     back to japanese, the auto switching will still be suspended.
  34.    
  35.         Limitations/Problems
  36.     Because the script uses image search to determine the input method, it is of course far from an universal
  37.     method. if your monitor has a resolution other than 1920x1080 or even if your toolbar is
  38.     a different size than mine, the image recongition might not work.
  39.     If that is the case, you will have to adjust the searched screen area and/or the NEEDLE image.
  40.     For the image, just Screenshot the big "A" in your toolbar that indicates alphanumeric input and
  41.     edit the background to a #000000 (R0 G0 B0) black.
  42.     Read comments in the code below for instructions on the screen search area.
  43.  
  44.     also blame pastebin for the wonky formatting. it looked fine in my editor
  45. _____________________________________________________________________________________________________________________
  46. */
  47.  
  48. #NoEnv
  49. SendMode Input
  50. SetWorkingDir %A_ScriptDir%
  51. if not FileExist("NEEDLE.png") {
  52.     msgbox,,お知らせ,in the description of this script I made clear in `nNO UNCERTAIN TERMS `nthat this script requires an image to be downloaded to the folder the script is located. `nin case you can actually read this`, consult the giant fancy description at the top of the script
  53.     ExitApp
  54. }
  55.  
  56.  
  57. jp := DllCall("LoadKeyboardLayout", "Str", "00000411", "Int", 1)
  58.  
  59. w := DllCall("GetForegroundWindow")
  60. pid := DllCall("GetWindowThreadProcessId", "UInt", w, "Ptr", 0)
  61. l := DllCall("GetKeyboardLayout", "UInt", pid)
  62.  
  63. ; SC03A equates to capslock but for some reason it doesn't want to recognise a normal capslock input
  64. ; the hotkey for kana/alphanumeric switch
  65. #If (l = jp)
  66. ~+SC03A::Pause,,1
  67. #If
  68.  
  69. ; the hotkey for language change
  70. ~+Alt::
  71. sleep,10
  72. start:
  73. w := DllCall("GetForegroundWindow")
  74. pid := DllCall("GetWindowThreadProcessId", "UInt", w, "Ptr", 0)
  75. l := DllCall("GetKeyboardLayout", "UInt", pid)
  76. if (l = jp) {
  77.     coordMode,Pixel
  78.     ; search area: upper left corner x1,y1, followed by bottom right corner x2,y2.
  79.     ; to easily get coords, run any ahk script, rclick on the taskbar icon and
  80.     ; select window spy. you need the "screen" coordinates
  81.     ;               x1   y1   x2   y2  
  82.     ImageSearch,FX,FY,1760,1050,1800,1080,*Trans000000 *100 NEEDLE.png  ; depending on your monitor resolution/taskbar size you might
  83.     ; Searched image needs to be called NEEDLE.png                  ; have to change the searched coordinates in this function and/or
  84.     if (FX != "") {                                         ; adjust the searched image. Screenshot the alphanumeric mode "A"
  85.         send, {ShiftDown}{CapsLock}{ShiftUp}                        ; and edit the background to black #000000 to correctly make the
  86.     }                                                       ; NEEDLE image. this image needs to be located in the script's
  87.     sleep,200 ; the delay between each image search                 ; folder.
  88.             ; if you don't run this on an actual potato
  89.             ; it should be able easily handle even
  90.             ; smaller intervals
  91.     goto,start
  92. }                                                          
  93. else {
  94.     return
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement