Jump to content

msgbox error -need help-


Recommended Posts

hi all

i have this small code

HotKeySet ("ش", "sh")
HotKeySet ("a", "a")
Func sh()
    MsgBox (0, "", "AR")
EndFunc

Func a()
    MsgBox(0, "", "EN")
EndFunc

While 1
    Sleep (1000)
WEnd

letter "a" is english

if u used and arabic language then pressed letter "a" you will have letter "ش"

so the same key on keyboard but it differ in output depends on what is the language u r using

Keyboard_arabic.jpg

when i run the script if the language was english at the moment i ran the script then i pressed "a"

it will give me a msgbox "EN"

 

and  when i run the script if the language was arabic at the moment i run the script then i pressed "ش"

it will give me a msgbox "AR"

and that is what i want..

the problem is if the language was english and i pressed "a" it will give "EN"

but when i switch language (and the script is still running) and make it arabic then i press "ش" it will still give me "EN"

if i closed the script then reopened it with arabic language then pressed "ش"  it will give arabic

so when i switch the lang when the script still running it will still give me a msgbox about the old lang

 

i want it to give me the right msgbox even if i switched the lang when the script is running

i hope u got the idea ?

 

Link to comment
Share on other sites

Hi,

Try this:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
 
_HotKey_Enable()
 
#region GUI
Local $hGUI = GUICreate("MyGUI")
 
GUIRegisterMsg($WM_INPUTLANGCHANGE, "WM_INPUTLANGCHANGE")
GUISetState(@SW_SHOW, $hGUI)
#endregion
 
While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd
 
GUIDelete($hGUI)

Func WM_INPUTLANGCHANGE($hWnd, $iMsg, $wParam, $lParam)
    HotKeySet("ش")
    HotKeySet("a")
    _HotKey_Enable()
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_INPUTLANGCHANGE
 
Func _HotKey_Enable()
    HotKeySet("ش", "sh")
    HotKeySet("a", "a")
EndFunc   ;==>_HotKey_Enable
 
Func sh()
    MsgBox(0, "", "AR")
EndFunc   ;==>sh
 
Func a()
    MsgBox(0, "", "EN")
EndFunc   ;==>a
Br, FireFox. Edited by FireFox
Link to comment
Share on other sites

 

try the macros in msgboxes: @OSLang  and  @KBLayout and tell us the results in each configuration. that might help.

this i mean:

.

MsgBox(0,@OSLang,@KBLayout)

 

tnx bro this is useful but the result differ from a country to another even if it is the same lang

so it won't work for me i want it to just look for the keyboard lang whatever the country is

I'd try using EnvUpdate.

it didn't work for me it hadn't done any

Hi,

Try this:

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
 
_HotKey_Enable()
 
#region GUI
Local $hGUI = GUICreate("MyGUI")
 
GUIRegisterMsg($WM_INPUTLANGCHANGE, "WM_INPUTLANGCHANGE")
GUISetState(@SW_SHOW, $hGUI)
#endregion
 
While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd
 
GUIDelete($hGUI)

Func WM_INPUTLANGCHANGE($hWnd, $iMsg, $wParam, $lParam)
    HotKeySet("ش")
    HotKeySet("a")
    _HotKey_Enable()
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_INPUTLANGCHANGE
 
Func _HotKey_Enable()
    HotKeySet("ش", "sh")
    HotKeySet("a", "a")
EndFunc   ;==>_HotKey_Enable
 
Func sh()
    MsgBox(0, "", "AR")
EndFunc   ;==>sh
 
Func a()
    MsgBox(0, "", "EN")
EndFunc   ;==>a
Br, FireFox.

 

tnx bo that works but it is too complicated to me i'm still new to autoit is there is a way without using GUI ?

Link to comment
Share on other sites

tnx bo that works but it is too complicated to me i'm still new to autoit is there is a way without using GUI ?

Just hide the GUI, remove the GUISetState function ;) Edited by FireFox
Link to comment
Share on other sites

Just hide the GUI, remove the GUISetState function ;)

what about this code ?

HotKeySet ("a", "a")

While 1
Sleep (100)
WEnd


Func a()
$hWnd = 0
Local $aRet = DllCall('user32.dll', 'long', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0)
$aRet = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', $aRet[0])
Global $var = Hex($aRet[0], 4)
if $var = 2801 then MsgBox(0, "", "AR")
if $var = 0409 then MsgBox(0, "", "EN")
EndFunc

it workes for me without restarting the script

bit it give the old lang 2 times 

i mean if the lang was EN then i pressed "A" it will msgbox "EN" and when i switched it to AR then pressed "a" it will msgbox "EN"

but at the second time i press "A" without changing lang wit will give the right choice a

any ideas ?

Edited by alexander95

Link to comment
Share on other sites

what about this code ?

HotKeySet ("a", "a")

While 1
Sleep (100)
WEnd


Func a()
$hWnd = 0
Local $aRet = DllCall('user32.dll', 'long', 'GetWindowThreadProcessId', 'hwnd', $hWnd, 'ptr', 0)
$aRet = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', $aRet[0])
Global $var = Hex($aRet[0], 4)
if $var = 2801 then MsgBox(0, "", "AR")
if $var = 0409 then MsgBox(0, "", "EN")
EndFunc

it workes for me without restarting the script

bit it give the old lang 2 times 

i mean if the lang was EN then i pressed "A" it will msgbox "EN" and when i switched it to AR then pressed "a" it will msgbox "EN"

but at the second time i press "A" without changing lang wit will give the right choice a

any ideas ?

.

just fyi: your solution is the same as mine - @KBLayout

E

 

then just make a loop and do the function twice and then the msgbox ;)

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

looking deeper into your code ..... makes me wonder you force a hexadecimal expression and then use it as a number and not a string and not a hex ....... very mysterious how that gets you a correct result.

 

.

$aRet = DllCall('user32.dll', 'long', 'GetKeyboardLayout', 'long', 0)
MsgBox(0,@KBLayout,Hex($aRet[0],4))
Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

it is hard to help, because we cannot reproduce the problem, but try this:

.

;http://www.autoitscript.com/forum/topic/153257-msgbox-error-need-help/#entry1102671
;Post #8
;D:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\SLICER\Avatar\photo-thumb-80182.gif
;by alexander95

;Script grabbed by SLICER by Edano here: http://www.autoitscript.com/forum/topic/152402-slicer-autoit-forum-script-grabber/?p=1093575

HotKeySet ("a", "a")

While 1
    Sleep (100)
WEnd

Func a()
    $var=@KBLayout
    $var=@KBLayout;    =====>  call it twice ?
    if $var = 2801 then MsgBox(0, "", "AR")
    if $var = 0409 then MsgBox(0, "", "EN")
EndFunc

.

E

 

or use melba's luxus version, technically the best solution:

.

;http://www.autoitscript.com/forum/topic/153257-msgbox-error-need-help/#entry1102671
;Post #4
;D:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\SLICER\Avatar\photo-thumb-42741.jpg
;by FireFox

;Script grabbed by SLICER by Edano here: http://www.autoitscript.com/forum/topic/152402-slicer-autoit-forum-script-grabber/?p=1093575

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

_HotKey_Enable()

#region GUI
Local $hGUI = GUICreate("MyGUI")

GUIRegisterMsg($WM_INPUTLANGCHANGE, "WM_INPUTLANGCHANGE")
;GUISetState(@SW_SHOW, $hGUI)
#endregion

While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd

;GUIDelete($hGUI)

Func WM_INPUTLANGCHANGE($hWnd, $iMsg, $wParam, $lParam)
    HotKeySet("Ø´")
    HotKeySet("a")
    _HotKey_Enable()

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_INPUTLANGCHANGE

Func _HotKey_Enable()
    HotKeySet("Ø´", "sh")
    HotKeySet("a", "a")
EndFunc   ;==>_HotKey_Enable

Func sh()
    MsgBox(0, "", "AR")
EndFunc   ;==>sh

Func a()
    MsgBox(0, "", "EN")
EndFunc   ;==>a
Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

it is hard to help, because we cannot rreproduce the problem, but try this:

.

;http://www.autoitscript.com/forum/topic/153257-msgbox-error-need-help/#entry1102671
;Post #8
;D:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\SLICER\Avatar\photo-thumb-80182.gif
;by alexander95

;Script grabbed by SLICER by Edano here: http://www.autoitscript.com/forum/topic/152402-slicer-autoit-forum-script-grabber/?p=1093575

HotKeySet ("a", "a")

While 1
    Sleep (100)
WEnd

Func a()
    $var=@KBLayout
    $var=@KBLayout;    =====>  call it twice ?
    if $var = "2801" then MsgBox(0, "", "AR")
    if $var = "0409" then MsgBox(0, "", "EN")
EndFunc

.

E

 

it didnt worked at all when i press "a" nothing happens 

Link to comment
Share on other sites

yes it is the only working but u cant fully understand it

i can't write think i don't understand to my script it will make more problems

.

did you try my edited version again ????

ok i repost it once again. seem to be communication problems.

.

;http://www.autoitscript.com/forum/topic/153257-msgbox-error-need-help/#entry1102671
;Post #8
;D:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\SLICER\Avatar\photo-thumb-80182.gif
;by alexander95

;Script grabbed by SLICER by Edano here: http://www.autoitscript.com/forum/topic/152402-slicer-autoit-forum-script-grabber/?p=1093575

HotKeySet ("a", "a")

While 1
    Sleep (100)
WEnd

Func a()
    $var=@KBLayout
    $var=@KBLayout;    =====>  call it twice ?
    if $var = 2801 then MsgBox(0, "", "AR")
    if $var = 0409 then MsgBox(0, "", "EN")
EndFunc
Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Link to comment
Share on other sites

 

.

did you try my edited version again ????

ok i repost it once again. seem to be communication problems.

.

;http://www.autoitscript.com/forum/topic/153257-msgbox-error-need-help/#entry1102671
;Post #8
;D:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\SLICER\Avatar\photo-thumb-80182.gif
;by alexander95

;Script grabbed by SLICER by Edano here: http://www.autoitscript.com/forum/topic/152402-slicer-autoit-forum-script-grabber/?p=1093575

HotKeySet ("a", "a")

While 1
    Sleep (100)
WEnd

Func a()
    $var=@KBLayout
    $var=@KBLayout;    =====>  call it twice ?
    if $var = 2801 then MsgBox(0, "", "AR")
    if $var = 0409 then MsgBox(0, "", "EN")
EndFunc

it only works for EN it never gives AR

Link to comment
Share on other sites

or use melba's luxus version

hm??

 

yes it is the only working but u cant fully understand it

i can't write think i don't understand to my script it will make more problems

I added some comments :

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
 
; Call the function to set the hotkeys
_HotKey_Enable()
 
; Create a hidden GUI and register to the INPUTLANGCHANGE window message.
; This WM (Window Message) will trigger its function when the user changes its keyboard layout.
#region GUI
Local $hGUI = GUICreate("MyGUI")
 
GUIRegisterMsg($WM_INPUTLANGCHANGE, "WM_INPUTLANGCHANGE")
#endregion
 
; Keep the script alive
While 1
    Sleep(10)
WEnd
 
Func WM_INPUTLANGCHANGE($hWnd, $iMsg, $wParam, $lParam)
    ; Unset the hotkeys
    HotKeySet("ش")
    HotKeySet("a")
    
    ; Re-set the hotkeys
    _HotKey_Enable()
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_INPUTLANGCHANGE
 
Func _HotKey_Enable()
    HotKeySet("ش", "sh")
    HotKeySet("a", "a")
EndFunc   ;==>_HotKey_Enable
 
Func sh()
    MsgBox(0, "", "AR")
EndFunc   ;==>sh
 
Func a()
    MsgBox(0, "", "EN")
EndFunc   ;==>a
All clear? :)

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...