Switchable Shift Ctrl Alt OSK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rakibkhan7496
Posts: 8
Joined: 11 May 2021, 06:53
Contact:

Switchable Shift Ctrl Alt OSK

11 May 2021, 14:12

I found a working onscreenkeyboard/OSK from a link and modified as MinKey named custom layout. It contains only 8 keys (backspace, delete, space, tab, enter, shift, control and alter). Everything is working but I want to make shift, ctrl, alt key to be held down until clicked again. But don't know how to do things. Basically I want to use mouse only while working on photoshop, so shift ctrl alt keys needs to be held down forever till I switch off. Any help?

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
#SingleInstance, Force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Menu, Tray, Icon, n.ico ; Menu and Tray Icon
;Keyboard layout: [key name, width, spacing]
OSK()
OSK() {
  static NewName:={"🢀":"BS", "✖":"Delete" }
  w1:=40, h1:=25
  s1:=[["🢀",w1-22],["✖",w1-22],["Enter",w1] ]
  s2:=[["Tab",w1-8],["Space",w1+6]]
  s3:=[["Esc",w1-10],["Shift",w1*1.2]]
  s4:=[["Ctrl",w1],["Alt",w1]]

  Gui, OSK: Destroy
  ; +E0x08000000  Click not to activate
  Gui, OSK: +AlwaysOnTop +Owner +E0x08000000
  Gui, OSK: Font, s10, Verdana
  Gui, OSK: Margin, 0, 0
  Gui, OSK: Color, DDEEFF
  Loop, 4 {
    if (A_Index<=2)
      j=
    For i,v in s%A_Index%
    {
      w:=v.2 ? v.2 : w1, d:=v.3 ? v.3 : 2
      j:=j="" ? "xm" : i=1 ? "xm y+2" : "x+" d
      Gui, OSK: Add, Button, %j% w%w% h%h1% -Wrap gRunOSK, % v.1
    }
  }
  Gui, OSK: Show, NA, NKey
  return

  OSKGuiClose:
    Gui, OSK: Minimize
  return

  RunOSK:
    k:=A_GuiControl
    s:=InStr(k," ") ? SubStr(k,0) : k
    s:=(v:=NewName[s]) ? v : s, s:="{" s "}"
    If A_GuiControl in Shift,Ctrl,Alt,Space
      Send % "{" A_GuiControl " " (GetKeyState(A_GuiControl) ? "up" : "down") "}"
    Else SendInput, {Blind}%s%
      return

  }

Link: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=58366


Code and Image Updated.
Solved :bravo: :dance: :clap: :superhappy:
MinKey.png
MinKey.png (1.83 KiB) Viewed 190 times
Last edited by rakibkhan7496 on 12 May 2021, 04:28, edited 1 time in total.
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Switchable Shift Ctrl Alt OSK  Topic is solved

11 May 2021, 18:51

You can replace the SendInput line with the following.

Code: Select all

If A_GuiControl in Shift,Ctrl,Alt
 Send % "{" A_GuiControl " " (GetKeyState(A_GuiControl) ? "up" : "down") "}"
Else SendInput, {Blind}%s%
rakibkhan7496
Posts: 8
Joined: 11 May 2021, 06:53
Contact:

Re: Switchable Shift Ctrl Alt OSK

12 May 2021, 04:32

mikeyww wrote:
11 May 2021, 18:51
You can replace the SendInput line with the following.

Code: Select all

If A_GuiControl in Shift,Ctrl,Alt
 Send % "{" A_GuiControl " " (GetKeyState(A_GuiControl) ? "up" : "down") "}"
Else SendInput, {Blind}%s%
Thank you very much for your effort. But can you somehow edit this script to highlight held key with color or something? I believe this code can be very useful someday.
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Switchable Shift Ctrl Alt OSK

12 May 2021, 06:25

Code: Select all

OSK()

OSK() {
  static NewName:={"🢀":"BS", "✖":"Delete" }
  w1:=40, h1:=25
  s1:=[["🢀",w1-22],["✖",w1-22],["Enter",w1] ]
  s2:=[["Tab",w1-8],["Space",w1+6]]
  s3:=[["Esc",w1-10],["Shift",w1*1.2]]
  s4:=[["Ctrl",w1],["Alt",w1]]

  Gui, OSK: Destroy
  Gui, OSK: +AlwaysOnTop +Owner +E0x08000000
  Gui, OSK: Font, s10, Verdana
  Gui, OSK: Margin, 0, 0
  Gui, OSK: Color, DDEEFF
  Loop, 4 {
    j := A_Index <= 2 ? "" : j
    For i,v in s%A_Index%
    {
      w := v.2 ? v.2 : w1, d := v.3 ? v.3 : 2
      j := j="" ? "xm" : i=1 ? "xm y+2" : "x+" d, held(v.1, False)
      Gui, OSK: Add, Button, %j% w%w% h%h1% -Wrap gRunOSK, % v.1
    }
  }
  Gui, OSK: Show, NA, NKey
  return

  OSKGuiClose:
    Gui, OSK: Minimize
  return

  RunOSK:
    k := A_GuiControl
    s := InStr(k," ") ? SubStr(k,0) : k
    s := (v:=NewName[s]) ? v : s, s:="{" s "}"
    If A_GuiControl in Shift,Ctrl,Alt,Space
      Send % "{" A_GuiControl ((pressed := GetKeyState(A_GuiControl)) ? " up" : " down") "}"
           . held(A_GuiControl, !pressed)
    Else Send {Blind}%s%
  Return
}

held(control, on := True) {
 Gui, Color, % on ? "Red" : "Default"
 Gui, Font, % "s10 " (on ? "w700" : "w400")
 GuiControl, Font, %control%
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 297 guests