Page 1 of 1

PassWordRequester with keyboard access [Resolved]

Posted: Fri Feb 13, 2009 11:21 am
by Kwai chang caine
Hello at all

I want to create a PassWordRequester but only if i push the CTRL key in the time where i launch my application.

But the problem, is that when i press the key CTRL in the same time that i run the code, my windows loose the focus :?

It's funny but the TextGadget have the focus and not the windows :shock:
You believe you have the focus, but if you press any key, there are not character who appears :cry:

This is the code who don't work :cry:

Code: Select all

  
Procedure.s InputBox(Prompt$, TexteDefaut$, Password) 

 Enumeration 
  #FormMsgBox 
  #GadgetLabel 
  #GadgetText 
  #GadgetBoutonOk 
 EndEnumeration 
  
 Hwnd = OpenWindow(#FormMsgBox, 0, 0, 500, 100, "Entrée de données", #PB_Window_ScreenCentered|#PB_Window_BorderLess) 
 TextGadget(#GadgetLabel, 15, 8, 460, 30, Prompt$, #PB_Text_Center) 
  
 If Password = 1 
  Flags = #PB_String_Password 
 EndIf 
  
 StringGadget(#GadgetText, 15, 35, 460, 20, TexteDefaut$, Flags) 
 ButtonGadget(#GadgetBoutonOk, 365, 70, 60, 23, "OK") 
 StickyWindow(#FormMsgBox, #True) 
 Delay(500) 
 SetFocus_(Hwnd) 
    
 Repeat 
  
  Ev = WaitWindowEvent() 
    
  If (Ev = #PB_Event_Gadget And EventGadget() = #GadgetBoutonOk) 
   Text$ = GetGadgetText(#GadgetText) 
   Break 
  EndIf 
  
 ForEver 
  
 CloseWindow(#FormMsgBox) 
 ProcedureReturn Text$ 

EndProcedure 

If GetAsyncKeyState_(#VK_CONTROL) < 0 
 CodeAcces$ = InputBox("Veuillez entrer le code d'acces", "", #True) 
 Debug CodeAcces$ 
Else 
 MessageRequester("Essai", "Ok pas de mot de passe") 
EndIf 
A friend STEFOU (to the french forum) find to me a solution.
It's to simulate a click on the windows in a loop 8)
It's works fine, but him and i knows it's not a really nice solution :oops:
Have you a better way to do that ??? :roll:

This is the code who work's fine :D

Code: Select all

Procedure.s InputBox(Prompt$, TexteDefaut$) 
  
 Enumeration 
  #FormMsgBox 
  #GadgetLabel 
  #GadgetText 
  #GadgetBoutonOk 
 EndEnumeration 
  
 OpenWindow(#FormMsgBox, 0, 0, 500, 100, "Entrée de données", #PB_Window_ScreenCentered|#PB_Window_BorderLess) 
 TextGadget(#GadgetLabel, 15, 8, 460, 30, Prompt$, #PB_Text_Center) 
 AddKeyboardShortcut(#FormMsgBox, #PB_Shortcut_Return, 13) ; Pour Return 
  
 StringGadget(#GadgetText, 15, 35, 460, 20, TexteDefaut$, #PB_String_Password) 
 ButtonGadget(#GadgetBoutonOk, 365, 70, 60, 23, "OK") 
 StickyWindow(#FormMsgBox, #True) 
 x = WindowX(#FormMsgBox) 
 y = WindowY(#FormMsgBox) 
 SetCursorPos_(x,y) 

 Repeat 
  mouse_event_(#MOUSEEVENTF_ABSOLUTE | #MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) 
  mouse_event_(#MOUSEEVENTF_ABSOLUTE | #MOUSEEVENTF_LEFTUP, x, y, 0, 0) 
  Delay(10) 
 Until GetActiveWindow() = #FormMsgBox 
  
 SetActiveGadget(#GadgetText) 
    
 Repeat 
    
  Ev = WaitWindowEvent() 
  
  If (Ev = #PB_Event_Gadget And EventGadget() = #GadgetBoutonOk) Or (Ev = #PB_Event_Menu And EventMenu() = 13) 
   Break 
  EndIf 
  
 ForEver 
  
 CodeAcces$ = GetGadgetText(#GadgetText) 
 CloseWindow(#FormMsgBox) 
 ProcedureReturn CodeAcces$ 
  
EndProcedure 

If GetAsyncKeyState_(#VK_CONTROL) < 0 
 Debug InputBox("Veuillez entrer le code d'acces", "") 
Else 
 MessageRequester("Essai", "Ok pas de mot de passe") 
EndIf
Thanks for your help
Good day

Posted: Fri Feb 13, 2009 1:55 pm
by gnozal
Something like this ?

Code: Select all

Procedure.s InputBox(Prompt$, TexteDefaut$, Password) 
  
  Enumeration 
    #FormMsgBox 
    #GadgetLabel 
    #GadgetText 
    #GadgetBoutonOk 
  EndEnumeration 
  
  hwnd = OpenWindow(#FormMsgBox, 0, 0, 500, 100, "Entrée de données", #PB_Window_ScreenCentered|#PB_Window_BorderLess) 
  TextGadget(#GadgetLabel, 15, 8, 460, 30, Prompt$, #PB_Text_Center) 
  
  If Password = 1 
    flags = #PB_String_Password 
  EndIf 
  
  StringGadget(#GadgetText, 15, 35, 460, 20, TexteDefaut$, flags) 
  ButtonGadget(#GadgetBoutonOk, 365, 70, 60, 23, "OK") 
  StickyWindow(#FormMsgBox, #True) 

  ; ----------------------------------
  SetForegroundWindow_(hwnd)
  SetActiveGadget(#GadgetText)
  ; ----------------------------------
  
  Repeat 
    
    Ev = WaitWindowEvent() 
    
    If (Ev = #PB_Event_Gadget And EventGadget() = #GadgetBoutonOk) 
      Text$ = GetGadgetText(#GadgetText) 
      Break 
    EndIf 
    
  ForEver 
  
  CloseWindow(#FormMsgBox) 
  ProcedureReturn Text$ 
  
EndProcedure 

If GetAsyncKeyState_(#VK_CONTROL) < 0 
  CodeAcces$ = InputBox("Veuillez entrer le code d'acces", "", #True) 
  Debug CodeAcces$ 
Else 
  MessageRequester("Essai", "Ok pas de mot de passe") 
EndIf

Posted: Fri Feb 13, 2009 3:50 pm
by Kwai chang caine
Thanks my good GNOZAL for your quick answer.
But apparently, you have do the same error that the SOLDAT INCONNU.

If you run the code and press the key CTRL in the same time AND try to write immediately with the keyboard without click on the window then that not works with your code too :cry:

Like i say before, it's funny because the cursor is in the stringgadget and the focus is in another place :shock:

For that your code works, you must be click with the mouse, one time, and the focus go to the password panel
After the keyboard write. :D

Posted: Fri Feb 13, 2009 4:04 pm
by gnozal
Kwaï chang caïne wrote:If you run the code and press the key CTRL in the same time AND try to write immediately with the keyboard without click on the window then that not works with your code too :cry:
I don't understand ...
You mean you cannot type characters while the control key is pressed ? This is a normal windows behaviour !? (because of CTRL+C, CTRL+V, etc...).
If you release the CTRL key when the password windows appears, you can type your password without any focus issue.

Posted: Fri Feb 13, 2009 5:47 pm
by Kwai chang caine
This is a normal windows behaviour !? (because of CTRL+C, CTRL+V, etc...).
No obviously i release the key before.
But when i press a new key, nothing appears :cry:

It's strange :shock:
In my PC with your code, i can't writing password if i don't clic on the windows before :shock:

But the second code that i have give, works fine on my PC, with this tips

Code: Select all

x = WindowX(#FormMsgBox) 
 y = WindowY(#FormMsgBox) 
 SetCursorPos_(x,y) 

 Repeat 
  mouse_event_(#MOUSEEVENTF_ABSOLUTE | #MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) 
  mouse_event_(#MOUSEEVENTF_ABSOLUTE | #MOUSEEVENTF_LEFTUP, x, y, 0, 0) 
  Delay(10) 
 Until GetActiveWindow() = #FormMsgBox 

Posted: Fri Feb 13, 2009 5:54 pm
by Kwai chang caine
I have try several time, and the focus is on the IDE of pure, or if i compile it is on the windows who is the EXE :cry:

Posted: Fri Feb 13, 2009 6:01 pm
by Rook Zimbabwe
Maybe I am issin gthis because the monitor I have at work is very bad... but...

Where do you SetActiveGadget(#Gadget) ??? of the password string gadget?

Posted: Fri Feb 13, 2009 6:10 pm
by Kwai chang caine
Yes the "SetActiveGadget(#Gadget)" is on the GadgetText

Code: Select all

StickyWindow(#FormMsgBox, #True) 

  ; ---------------------------------- 
  SetForegroundWindow_(hwnd) 
  SetActiveGadget(#GadgetText) 
  ; ---------------------------------- 

Posted: Sun Feb 15, 2009 12:47 pm
by Kwai chang caine
Nobody have a begin of beginning of start of a little small idea for me ???

For a time or KCC ask not the most difficult question of the world :oops:

Posted: Sun Feb 15, 2009 3:33 pm
by Sparkie
I added AttachThreadInput_() to gnozal's code and it works for me on XP.

Code: Select all

Procedure.s InputBox(Prompt$, TexteDefaut$, Password) 
  
  Enumeration 
    #FormMsgBox 
    #GadgetLabel 
    #GadgetText 
    #GadgetBoutonOk 
  EndEnumeration 
  
  hwnd = OpenWindow(#FormMsgBox, 0, 0, 500, 100, "Entrée de données", #PB_Window_ScreenCentered|#PB_Window_BorderLess) 
  TextGadget(#GadgetLabel, 15, 8, 460, 30, Prompt$, #PB_Text_Center) 
  
  If Password = 1 
    flags = #PB_String_Password 
  EndIf 
  
  StringGadget(#GadgetText, 15, 35, 460, 20, TexteDefaut$, flags) 
  ButtonGadget(#GadgetBoutonOk, 365, 70, 60, 23, "OK") 
  StickyWindow(#FormMsgBox, #True) 
  
  ; ---Sparkie was here--------------- 
  fgw = GetForegroundWindow_() 
  If fgw <> WindowID(#FormMsgBox) 
    externalThread = GetWindowThreadProcessID_(fgw, 0) 
    myThread = GetWindowThreadProcessID_(WindowID(#FormMsgBox),0) 
    AttachThreadInput_(externalThread, myThread, 1) 
    SetForegroundWindow_(hwnd) 
  EndIf 
  ; ---------------------------------- 
  SetActiveGadget(#GadgetText) 
  Repeat 
    
    Ev = WaitWindowEvent() 
    
    If (Ev = #PB_Event_Gadget And EventGadget() = #GadgetBoutonOk) 
      Text$ = GetGadgetText(#GadgetText) 
      Break 
    EndIf 
    
  ForEver 
  
  CloseWindow(#FormMsgBox) 
  
  If Text$ 
    MessageRequester("Password is", Text$ ) 
  Else 
    MessageRequester("No Password Entered", Text$ ) 
  EndIf 
  AttachThreadInput_(externalThread, myThread, 0) 
  
  ProcedureReturn Text$ 
  
EndProcedure 

If GetAsyncKeyState_(#VK_CONTROL) < 0 
  CodeAcces$ = InputBox("Veuillez entrer le code d'acces", "", #True) 
  
  
Else 
  MessageRequester("Essai", "Ok pas de mot de passe") 
EndIf

Posted: Mon Feb 16, 2009 11:18 am
by Kwai chang caine
Thanks MASTER SPARKIE 8)
I have believe that nobody can find a solution to this strange problem :roll:

I say strange , because i ask to me if on all the PC the behavior is the same ??? :roll:
Because MASTER GNOZAL give this solution and say it's all right :D
And for KCC it's not allright :cry:

I'm in my job and i'm on W2000.
I have try your code the dribble around my mouth and the IDE crashed :shock:
I have tried another time and it's the same behavior.

I have try With the 4.20 and the 4.30 and "kif kif" :cry: (In french/arabian = the same thing :wink:)
The red panel IDE appears and close directly the IDE :cry:
It's perhaps the fault of W2000 :roll:

Thanks when even for your help SPARKIE 8)
I'am happy to speak to you since this long time :D

Posted: Mon Feb 16, 2009 1:53 pm
by Sparkie
Sorry about that KCC. I tested using jaPBe and it works fine. I'll see if I can find the probelm that is causing the error with the PB IDE.

Posted: Mon Feb 16, 2009 2:14 pm
by Sparkie
The PB IDE doesn't like AttachThreadInput_(). Try creating an exe of the code and see what happens when running it as .exe. Works here on XP.

Posted: Mon Feb 16, 2009 2:57 pm
by Kwai chang caine
Yes you are right !!!! :D
The IDE don't like this function
With the EXE, it's work fine on W2000
Sorry about that KCC.
:shock:

Are you crazy :lol:
But if my poor IDE crash thanks to a code of my hero SPARKIE :D
It's an honor 8)
And for proof that, i have try three time :lol:

Furthermore .....my IDE is habituate :cry:
My code is always so good :oops:

"Pooouuiiinng" a code of KCC
"Pooouuiiinng" another code of KCC

All the day my neighboring hear "Pooouuiiinng","Pooouuiiinng","Pooouuiiinng".
And i'm sure, they believe, that i create a music program :D

Sometime my IDE crash hitself, when it see, that it's me who sit down ahead it :?

I thank you very much for your quick answer.
At the big pleasure to speak to you 8)