Page 1 of 1
Virtual Keyboard
Posted: Sun May 09, 2021 6:23 pm
by Lima
It is possible to have a virtual keyboard in PB such as
'Free Virtual Keyboard on
https://freevirtualkeyboard.com, among others?
My main question is how to send the pressed key to the active field of any application.
My thanks in advance to anyone who devotes some time to this matter.
Re: Virtual Keyboard
Posted: Sun May 09, 2021 6:59 pm
by Sicro
Have a look at my post signature:
PB-CodeArchiv-Rebirth/Keyboard_Mouse/SimulateKeyboardMouseInputs.pbi
Re: Virtual Keyboard
Posted: Sun May 09, 2021 8:58 pm
by Lima
Thank you very much Sicro.
But I think that I can't solve the problem with that software.
The clicked key must go to the application that has the focus at the moment of the click.
Thanks.
Re: Virtual Keyboard
Posted: Mon May 10, 2021 12:38 pm
by Sicro
Lima wrote: ↑Sun May 09, 2021 8:58 pm
But I think that I can't solve the problem with that software.
The clicked key must go to the application that has the focus at the moment of the click.
The trick now is to create a virtual keyboard window that doesn't steal focus from other windows.
Here is a code that creates a virtual keyboard with the letter keys "a" and "b":
Code: Select all
IncludeFile "Path to PB-CodeArchiv-Rebirth/Keyboard_Mouse/SimulateKeyboardMouseInputs.pbi"
Enumeration Window
#Window_Main
EndEnumeration
Enumeration Gadget
#Button_a
#Button_b
EndEnumeration
If Not OpenWindow(#Window_Main, 0, 0, 160, 100, "Virtual Keyboard")
Debug "Error: OpenWindow"
End
EndIf
; Prevent the window from being activated (getting the focus)
exStyle = GetWindowLong_(WindowID(#Window_Main), #GWL_EXSTYLE)
SetWindowLong_(WindowID(#Window_Main), #GWL_EXSTYLE, exStyle | #WS_EX_NOACTIVATE)
; Set window always on top of all other open windows
StickyWindow(#Window_Main, #True)
ButtonGadget(#Button_a, 15, 20, 50, 50, "a")
ButtonGadget(#Button_b, 95, 20, 50, 50, "b")
Repeat
event = WaitWindowEvent()
If event = #PB_Event_Gadget
Select EventGadget()
Case #Button_a
Simulate::ComputerKey('A', #True)
Simulate::ComputerKey('A', #False)
Case #Button_b
Simulate::ComputerKey('B', #True)
Simulate::ComputerKey('B', #False)
EndSelect
EndIf
Until event = #PB_Event_CloseWindow
Re: Virtual Keyboard
Posted: Mon May 10, 2021 1:56 pm
by Lima
You're right Sicro.
The solution was in your module.
This was the big problem "The trick now is to create a virtual keyboard window that doesn't steal focus from other windows"
My big thanks to you.
Re: Virtual Keyboard
Posted: Mon Jul 26, 2021 8:31 pm
by Lima
(PureBasic 5.73,Win 10, Portuguese keyboard)
With the code below I get Ã.
But the Chr(191)="¿" and Chr(126)="~".
Is it possible to match the character that the key displays and the Sendinput function?
Thank you
Code: Select all
OpenWindow(0, 0, 0, 300,200, "Virtual Keyboard")
ButtonGadget(10, 15, 55, 50, 30,"Test")
SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_NOACTIVATE)
; Set window always on top of all other open windows
StickyWindow(0, #True)
Debug "Tilde= "+Asc("~"); =126
Debug "Chr(191)= "+Chr(191); = ¿
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 10
TipTap.INPUT
TipTap\Type = #INPUT_KEYBOARD
TipTap\ki\wVk =191
TipTap\ki\dwFlags = 0
SendInput_(1, @TipTap, SizeOf(INPUT))
; TipTap\ki\wVk = 191
TipTap\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @TipTap, SizeOf(INPUT))
TipTap\ki\wVk = #VK_LSHIFT
TipTap\ki\dwFlags = 0
SendInput_(1, @TipTap, SizeOf(INPUT))
TipTap\ki\wVk ='A'
TipTap\ki\dwFlags = 0
SendInput_(1, @TipTap, SizeOf(INPUT))
; TipTap\ki\wVk = 'A'
TipTap\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @TipTap, SizeOf(INPUT))
TipTap\ki\wVk = #VK_LSHIFT
TipTap\ki\dwFlags = #KEYEVENTF_KEYUP
SendInput_(1, @TipTap, SizeOf(INPUT))
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
Re: Virtual Keyboard
Posted: Fri Jul 30, 2021 1:41 pm
by Sicro
Try this code:
Code: Select all
IncludeFile "Path to PB-CodeArchiv-Rebirth/Keyboard_Mouse/SendKeys[Win].pbi"
OpenWindow(0, 0, 0, 300,200, "Virtual Keyboard")
ButtonGadget(10, 15, 55, 50, 30,"Test")
SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_NOACTIVATE)
; Set window always on top of all other open windows
StickyWindow(0, #True)
Debug "Tilde= "+Asc("~"); =126
Debug "Chr(191)= "+Chr(191); = ¿
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 10
SendKeys(Chr(191) + "A")
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
Re: Virtual Keyboard
Posted: Sat Jul 31, 2021 12:25 pm
by Lima
Hello Sicro.
It works. Now I can send the ascii code of the key that the result matches.
Thank you for the help.
Re: Virtual Keyboard
Posted: Sun Aug 01, 2021 6:50 am
by Sicro
Glad to hear it. Then I know why it didn't work with the other module and can fix it.