Thursday, March 5, 2015

On-Screen Keyboard for POS

On a POS system, since we are dealing with touch screens, then we need to have a keyboard on screen so our users, in addition to barcode scanning, can do other more works.  And for that what we normally do is create our own on-screen keyboards.  Or utilize the built-in OSK that comes along with Windows that can be simply called via RUN /N OSK.EXE.

What is more appealing though is to make said OSK appear to be really a part of our form and this can be done via embedding said OSK.EXE within our form.  However, embedding Microsoft's OSK is easier said than done.

Good news then, here is an alternative to Microsoft's OSK (On-Screen Keyboard) that can be easily embedded inside our forms.  Further good news is that this one is free:

For the embedding need inside our form, I will refer you to the codes  graciously shared to us by a good friend Vilhelm-Ion Praisach.  In addition to the tricks he used there, I like his subtle touch here on the usage of a timer instead of my SLEEP() way on the embedding 3rd party apps within our forms blog.


* Author:  Vilhelm-Ion Praisach
* Date: March 4, 2015

Declare Integer ShellExecute In shell32 Integer hWindow, String lpOperation, String lpFile, String lpParameters, String lpDirectory, Integer nShowCmd
Declare Integer SetParent In User32 Integer HWnd, Integer ParenthWnd
Declare Integer FindWindow In user32 String lpClassName, String lpWindowName
Declare Integer GetWindowLong In user32 Integer HWnd, Integer nIndex
Declare Integer SetWindowLong In user32 Integer HWnd, Integer nIndex, Integer dwNewLong
Declare Integer SetFocus In user32 Integer
Declare Integer SetWindowPos In user32 INTEGER HWnd, INTEGER hWndInsertAfter, INTEGER x, INTEGER Y, INTEGER cx, INTEGER cy, INTEGER uFlags
Declare Integer GetWindowThreadProcessId in Win32API Integer hWnd, Integer @lpdwProcessId
Declare Integer OpenProcess in Win32API Integer dwDesiredAccess, Integer bInheritHandle, Integer dwProcessID
Declare Integer TerminateProcess in Win32API Integer hProcess, Integer uExitCode

Public ofrm
ofrm = Createobject("MyForm")

Define Class MyForm As Form
      Width = 900
      hOsk = 0
      nOskHeight = 200
      ShowWindow = 2
      Desktop = .T.
      AutoCenter = .T.
      Add Object txt As TextBox
      Add Object cmd As CommandButton With Top = 50 , Caption = "\<Click"
      Add Object tmr As Timer With Interval = 300
      Procedure Load
            = ShellExecute(0, "open", "freevk.exe", "", "", 1) && this should be inside among your VFP paths
      Procedure tmr.Timer
            LOCAL nStyle
            ThisForm.hOsk = FindWindow (.Null., "Free Virtual Keyboard (")
            nStyle = GetWindowLong (ThisForm.hOsk, -16)
            SetWindowLong (ThisForm.hOsk, -16, Bitset(m.nStyle,30)) && set child
            SetWindowLong (ThisForm.hOsk, -16, Bitclear(m.nStyle,31)) && remove popup
            SetParent(ThisForm.hOsk, Thisform.HWnd) && change parent
            SetWindowLong (ThisForm.hOsk, -16, BITAND(m.nStyle,2^32-1-0xCF0000)) && remove the title bar
            SetWindowPos(ThisForm.hOsk, 0, 0, ThisForm.Height-ThisForm.nOskHeight,ThisForm.width, ThisForm.nOskHeight,  0x0020+0x0040) && move to the bottom of the form and show

            This.Enabled = .F.
            SetFocus(Thisform.HWnd) && set focus to the VFP window
      PROCEDURE destroy
            LOCAL lnProcessID
            lnProcessID = 0       
            GetWindowThreadProcessId(ThisForm.hOsk, @lnProcessID)       
            TerminateProcess(OpenProcess(1, 1, m.lnProcessID) , 0)
      PROCEDURE resize
            SetWindowPos(ThisForm.hOsk, 0, 0, ThisForm.Height-ThisForm.nOskHeight,ThisForm.width, ThisForm.nOskHeight,  0x0020+0x0040+0x0010) && move to the bottom of the form, and show, and SWP_NOACTIVATE


Hope this helps!  Cheers!


  1. Thank full , EPOS he was new Way to help to us to get the business running sucessfull.

  2. Thanks for some good write ups. epos system like to see more from you.

  3. Really nice and helpful blog with a lot of information. epos system It could help a lot more for all those readers who want to know information about EPOS system. Thanks for sharing and keep posting more.