Variable problems [Beginner]

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Anfly
Posts: 12
Joined: 10 Sep 2022, 16:47

Variable problems [Beginner]

Post by Anfly » 27 Nov 2022, 21:07

I have 2 edit boxes that a user can type in their keyboard id for. I then use GuiControlGet to know what they put in their edit box and but it in keyboardId := AHI.GetKeyboardId(Vv, Pp), but i am getting errors and have no idea what I am doing wrong. (PID_var and VID_var have the same exact value as Vv and Pp)

Code: Select all

GuiControlGet,CurrentVID,1:,VID_var
GuiControlGet,CurrentPID,1:,PID_var

Vv := CurrentVID
Pp := CurrentPID

;Vv := 0x03F0 --Using this line of code, it works successfully but does not allow me to change it without editing the code
;Pp := 0x0591 --Same for here


keyboardId := AHI.GetKeyboardId(Vv, Pp) ;0x03F0, 0x0591
AHI.SendKeyEvent(keyboardId, GetKeySC("a"), 1)
I am guessing it is because CurrentVID and CurrentPID are strings or something, but I have no ideas why it works when I put in the values directly inside the code

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Variable problems [Beginner]

Post by mikeyww » 27 Nov 2022, 21:52

Hi,

You are having trouble with a GUI but did not post the code for it. I think it would help the reader.

A few simple tips:
1. If you'd like to know the value of a variable, you can use MsgBox to display it. Easy. MsgBox There is no need to guess what is happening. You can use debugging strategies to find out.

2. One simple way to get the values from GUI controls (with variables) is to submit the GUI. Easy again.

https://www.autohotkey.com/docs/commands/Gui.htm#Submit
PID_var and VID_var have the same exact value as Vv and Pp.
How do you know? Prove it (and show your code).

Anfly
Posts: 12
Joined: 10 Sep 2022, 16:47

Re: Variable problems [Beginner]

Post by Anfly » 28 Nov 2022, 12:04

I am currently at school and will show my code the moment I get home. I used an edit box and i am used msgbox and tooltip to show me PID_Var and VID_Var for them to be the same. Thank you for your response

Anfly
Posts: 12
Joined: 10 Sep 2022, 16:47

Re: Variable problems [Beginner]

Post by Anfly » 28 Nov 2022, 16:22

mikeyww wrote:
27 Nov 2022, 21:52
Hi,

You are having trouble with a GUI but did not post the code for it. I think it would help the reader.

A few simple tips:
1. If you'd like to know the value of a variable, you can use MsgBox to display it. Easy. MsgBox There is no need to guess what is happening. You can use debugging strategies to find out.

2. One simple way to get the values from GUI controls (with variables) is to submit the GUI. Easy again.

https://www.autohotkey.com/docs/commands/Gui.htm#Submit
PID_var and VID_var have the same exact value as Vv and Pp.
How do you know? Prove it (and show your code).
Here is the code :

Code: Select all

#include <AutoHotInterception>
#SingleInstance Force
#NoEnv
#Persistent
#Warn
#HotkeyInterval 99000000
#MaxHotkeysPerInterval 99000000
#InstallKeybdHook
#MaxMem 256
#Warn UseEnv, Off
#KeyHistory 0
#ErrorStdOut
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
DetectHiddenWindows Off
FileEncoding UTF-16
Process Priority,, High
SetWinDelay -1
SetControlDelay -1
SetKeyDelay -1, -1
SetMouseDelay -1
SetDefaultMouseSpeed 0
ListLines Off
CoordMode, Pixel, Screen
global AHI := new AutoHotInterception()
;=============================================
full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
IniRead,keyVID,%A_ScriptFullPath%:Stream:$DATA, Keyboard, vid
IniRead,keyPID,%A_ScriptFullPath%:Stream:$DATA, Keyboard, pid
if(keyVID == "ERROR" or keyPID == "ERROR")
{
keyVID := "0x03F0"
keyPID := "0x0591"
}
CurrentTap := "a"
;=====================================================
guiwidth := 730
Gui, Color, 808080
Gui, Margin, 0, 0
Gui Font, s8 Norm q0, Ms Shell Dlg 2
Gui, Add, Progress, % "x-1 y-1 w" (guiwidth+2) " h31 Background404040 Disabled hwndHPROG"
Gui Add, Edit, vVID_var x248 y312 w53 h21, %keyVID%
Gui Add, Edit, vPID_var x328 y312 w53 h21, %keyPID%
Gui Add, Button, gUpdate x8 y56 w94 h23, Update
WinSet, Region, 0-0 w730 h30 R30-15
Gui, -Caption
Gui Show, w730 h368, Private Channel V3.2
return

Update:
GuiControlGet,CurrentVID,1:,VID_var
GuiControlGet,CurrentPID,1:,PID_var
Vv := CurrentVID --does not work
Pp := CurrentPID --does not work

;Vv := 0x03F0 --works
;Pp := 0x0591 --works


;keyboardId := AHI.GetKeyboardId(Vv, Pp) ;0x03F0, 0x0591
;AHI.SendKeyEvent(keyboardId, GetKeySC(CurrentTap), 1)
return
I made with msgbox that both values are the same

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Variable problems [Beginner]

Post by mikeyww » 28 Nov 2022, 16:28

I checked your script for a MsgBox command. I did not find a single one.

Code: Select all

CurrentVID  = xyz`r
; CurrentVID  = xyz
Vv          = xyz
equal      := CurrentVID = Vv
MsgBox, 64, Result, CurrentVID = %CurrentVID%`n`nVv = %Vv%`n`nEqual = %equal%

Anfly
Posts: 12
Joined: 10 Sep 2022, 16:47

Re: Variable problems [Beginner]

Post by Anfly » 28 Nov 2022, 16:43

mikeyww wrote:
28 Nov 2022, 16:28
I checked your script for a MsgBox command. I did not find a single one.

Code: Select all

CurrentVID  = xyz`r
; CurrentVID  = xyz
Vv          = xyz
equal      := CurrentVID = Vv
MsgBox, 64, Result, CurrentVID = %CurrentVID%`n`nVv = %Vv%`n`nEqual = %equal%
Deppest apologies, I forgot to include it since it was not in this script, but a testing one.

Code: Select all

#include <AutoHotInterception>
#SingleInstance Force
#NoEnv
#Persistent
#Warn
#HotkeyInterval 99000000
#MaxHotkeysPerInterval 99000000
#InstallKeybdHook
#MaxMem 256
#Warn UseEnv, Off
#KeyHistory 0
#ErrorStdOut
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
DetectHiddenWindows Off
FileEncoding UTF-16
Process Priority,, High
SetWinDelay -1
SetControlDelay -1
SetKeyDelay -1, -1
SetMouseDelay -1
SetDefaultMouseSpeed 0
ListLines Off
CoordMode, Pixel, Screen
global AHI := new AutoHotInterception()
;=============================================
full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
IniRead,keyVID,%A_ScriptFullPath%:Stream:$DATA, Keyboard, vid
IniRead,keyPID,%A_ScriptFullPath%:Stream:$DATA, Keyboard, pid
if(keyVID == "ERROR" or keyPID == "ERROR")
{
keyVID := "0x03F0"
keyPID := "0x0591"
}
CurrentTap := "a"
;=====================================================
guiwidth := 730
Gui, Color, 808080
Gui, Margin, 0, 0
Gui Font, s8 Norm q0, Ms Shell Dlg 2
Gui, Add, Progress, % "x-1 y-1 w" (guiwidth+2) " h31 Background404040 Disabled hwndHPROG"
Gui Add, Edit, vVID_var x248 y312 w53 h21, %keyVID%
Gui Add, Edit, vPID_var x328 y312 w53 h21, %keyPID%
Gui Add, Button, gUpdate x8 y56 w94 h23, Update
WinSet, Region, 0-0 w730 h30 R30-15
Gui, -Caption
Gui Show, w730 h368, Private Channel V3.2
return

Update:
GuiControlGet,CurrentVID,1:,VID_var
GuiControlGet,CurrentPID,1:,PID_var
Vv := CurrentVID --does not work
Pp := CurrentPID --does not work

;Vv := 0x03F0 --works
;Pp := 0x0591 --works

if(CurrentVID = Vv)
tooltip, equal
else
tooltip, not equal

msgbox, CurrentVID : %CurrentVID% | CurrentPID : %CurrentPID% || Vv : %Vv% | Pp : %Pp% 

keyboardId := AHI.GetKeyboardId(Vv, Pp) ;0x03F0, 0x0591
AHI.SendKeyEvent(keyboardId, GetKeySC(CurrentTap), 1)
return

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Variable problems [Beginner]

Post by mikeyww » 28 Nov 2022, 16:58

If you are seeing "equal", then I'm stumped & will be eager to see what the experts think. :eh: :think: :wtf:

Is it possible that the value is being read from the INI file but has an invisible character?
Last edited by mikeyww on 28 Nov 2022, 17:04, edited 1 time in total.

Anfly
Posts: 12
Joined: 10 Sep 2022, 16:47

Re: Variable problems [Beginner]

Post by Anfly » 28 Nov 2022, 17:01

mikeyww wrote:
28 Nov 2022, 16:58
If you are seeing "equal", then I'm stumped & will be eager to see what the experts think. :eh: :think: :wtf:

One question: what does "works" mean?
It presses a and gives no errors. Here is an example of "not working". Also, i am almost 100% certain it is because its a string and not an integer, so im testing my theory out, but there has been not alot of ahk forums talking about string to integer conversion.
image.png
image.png (19.2 KiB) Viewed 480 times

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Variable problems [Beginner]

Post by mikeyww » 28 Nov 2022, 17:05

What is the value of (keyVID == "ERROR" or keyPID == "ERROR")? If you display the value, is it true or false immediately after IniRead?

Anfly
Posts: 12
Joined: 10 Sep 2022, 16:47

Re: Variable problems [Beginner]

Post by Anfly » 28 Nov 2022, 17:25

mikeyww wrote:
28 Nov 2022, 17:05
What is the value of (keyVID == "ERROR" or keyPID == "ERROR")? If you display the value, is it true or false immediately after IniRead?
I made sure both keyVID and keyPID are the same, and even removed iniread and directly the values for keyPID and VID. Both do not work

User avatar
mikeyww
Posts: 26595
Joined: 09 Sep 2014, 18:38

Re: Variable problems [Beginner]

Post by mikeyww » 28 Nov 2022, 17:28

Ok. I'll quit here!

Could see lexikos posts about strings, though not sure whether related. A good thought.

Post Reply

Return to “Ask for Help (v1)”