Loading ...
Sorry, an error occurred while loading the content.
 

RE: [libertybasic] sendkeys

Expand Messages
  • Stefan Pendl
    ... There is the keybd_event API function to do this. Searching the group online will return many hits containing example code. ... Stefan Pendl
    Message 1 of 8 , Aug 10, 2010
      >
      > Hi
      > I have a program (geneweb genealogy) partly dos-based. In a
      > dos-window a value should be entered and after that the
      > enter-key on the keybord should be pressed.
      > Instead I would like to send the key-code via a lb-program.
      > Has Liberty Basic 4.03 or 4.04 this ability and has anybody a
      > snippet showing how it can be done.
      > Ingemar
      >

      There is the keybd_event API function to do this.

      Searching the group online will return many hits containing example code.

      ---
      Stefan Pendl
      http://stefanpendl.runbasichosting.com/

      Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
      Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

      Books at http://www.lulu.com/ and http://www.amazon.com/
      Alyce Watson ... APIs for Liberty BASIC
      Carl Gundel .... Beginning Programming with Liberty BASIC

      Windows 7 Home Premium 64-bit RTM
      AMD Turion X2 RM-70 2GHz, 4GB RAM
    • Gordon
      Hello, Have you tried Inkey$? and the ASC values? Gordon
      Message 2 of 8 , Aug 10, 2010
        Hello,

        Have you tried Inkey$?
        and the ASC values?

        Gordon

        --- In libertybasic@yahoogroups.com, "ingbje" <ingbje@...> wrote:
        >
        > Hi
        > I have a program (geneweb genealogy) partly dos-based. In a dos-window a value should be entered and after that the enter-key on the keybord should be pressed.
        > Instead I would like to send the key-code via a lb-program. Has Liberty Basic 4.03 or 4.04 this ability and has anybody a snippet showing how it can be done.
        > Ingemar
        >
      • Ingemar Bjerle
        Thanks for the help I got. The advice Stefan gav me was very helpful. The result of the information and some work of my grand son gave the snippet below:
        Message 3 of 8 , Aug 10, 2010
          Thanks for the help I got. The advice Stefan gav me was very helpful.
          The result of the information and some work of my grand son gave the snippet below:
          Ingemar

          ' The Program presses the enter-key efter two seconds.
          call pause 2000
          call keybdEvent 13, 1
          call keybdEvent 13, 0

          end

          sub pause mil
          tcurrent = time$("milliseconds")
          timeout = tcurrent + mil
          if timeout > 86400000 then ' roll over at midnight
          timeout = timeout - 86400000
          do
          tcurrent = time$("milliseconds")
          loop until (86400000 - tcurrent) > 1000000
          end if

          do
          tcurrent = time$("milliseconds")
          loop until (tcurrent >= timeout)

          end sub

          sub keybdEvent bVk, depressed
          if depressed = 0 then dwFlags = _KEYEVENTF_KEYUP

          calldll #user32, "keybd_event",_
          bVk as ushort,_
          bScan as ushort,_
          dwFlags as ulong,_
          dwExtraInfo as ulong,_
          result as void
          end sub

          ----- Original Message -----
          From: Gordon
          To: libertybasic@yahoogroups.com
          Sent: Tuesday, August 10, 2010 11:08 PM
          Subject: [libertybasic] Re: sendkeys




          Hello,

          Have you tried Inkey$?
          and the ASC values?

          Gordon

          --- In libertybasic@yahoogroups.com, "ingbje" <ingbje@...> wrote:
          >
          > Hi
          > I have a program (geneweb genealogy) partly dos-based. In a dos-window a value should be entered and after that the enter-key on the keybord should be pressed.
          > Instead I would like to send the key-code via a lb-program. Has Liberty Basic 4.03 or 4.04 this ability and has anybody a snippet showing how it can be done.
          > Ingemar
          >





          [Non-text portions of this message have been removed]
        • Stefan Pendl
          ... --snip ... --snip Below find a better pause procedure, which will not hog CPU cycles during the pause duration. ---code start (watch for line wraps) sub
          Message 4 of 8 , Aug 11, 2010
            >
            > Thanks for the help I got. The advice Stefan gav me was very helpful.
            > The result of the information and some work of my grand son
            > gave the snippet below:
            > Ingemar
            >

            --snip

            >
            > sub pause mil
            > tcurrent = time$("milliseconds")
            > timeout = tcurrent + mil
            > if timeout > 86400000 then ' roll over at midnight
            > timeout = timeout - 86400000
            > do
            > tcurrent = time$("milliseconds")
            > loop until (86400000 - tcurrent) > 1000000
            > end if
            >
            > do
            > tcurrent = time$("milliseconds")
            > loop until (tcurrent >= timeout)
            >
            > end sub
            >

            --snip

            Below find a better pause procedure, which will not hog CPU cycles during the pause duration.

            '---code start (watch for line wraps)
            sub Pause seconds
            ' halt program execution for specified period
            milliseconds = int(seconds * 1000)

            calldll #kernel32, "Sleep",_
            milliseconds as ulong,_
            result as void
            end sub
            '---code end

            ---
            Stefan Pendl
            http://stefanpendl.runbasichosting.com/

            Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
            Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

            Books at http://www.lulu.com/ and http://www.amazon.com/
            Alyce Watson ... APIs for Liberty BASIC
            Carl Gundel .... Beginning Programming with Liberty BASIC

            Windows 7 Home Premium 64-bit RTM
            AMD Turion X2 RM-70 2GHz, 4GB RAM
          • Ingemar Bjerle
            Hi Thanks again for your timersnip. I am normally using the LB-timer. Is your time better than the LB-timer? Now I have three timers to choose between. My
            Message 5 of 8 , Aug 11, 2010
              Hi
              Thanks again for your timersnip. I am normally using the LB-timer. Is your time better than the LB-timer?
              Now I have three timers to choose between. My state of mind was more relaxed when I only knew about one timer.

              The reason I have to use timers is that three programs should open after another and without timer they open almost simultaneously
              and interfear with each other. If I issue the sendkey-return to early the return-key will not be actuated. I have a 4 year old PC not very fast.
              I wonder if I will have the same problems running on a faster PC.

              kind regards
              Ingemar

              ----- Original Message -----
              From: Stefan Pendl
              To: libertybasic@yahoogroups.com
              Sent: Wednesday, August 11, 2010 9:45 AM
              Subject: RE: [libertybasic] sendkeys



              >
              > Thanks for the help I got. The advice Stefan gav me was very helpful.
              > The result of the information and some work of my grand son
              > gave the snippet below:
              > Ingemar
              >

              --snip

              >
              > sub pause mil
              > tcurrent = time$("milliseconds")
              > timeout = tcurrent + mil
              > if timeout > 86400000 then ' roll over at midnight
              > timeout = timeout - 86400000
              > do
              > tcurrent = time$("milliseconds")
              > loop until (86400000 - tcurrent) > 1000000
              > end if
              >
              > do
              > tcurrent = time$("milliseconds")
              > loop until (tcurrent >= timeout)
              >
              > end sub
              >

              --snip

              Below find a better pause procedure, which will not hog CPU cycles during the pause duration.

              '---code start (watch for line wraps)
              sub Pause seconds
              ' halt program execution for specified period
              milliseconds = int(seconds * 1000)

              calldll #kernel32, "Sleep",_
              milliseconds as ulong,_
              result as void
              end sub
              '---code end

              ---
              Stefan Pendl
              http://stefanpendl.runbasichosting.com/

              Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
              Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

              Books at http://www.lulu.com/ and http://www.amazon.com/
              Alyce Watson ... APIs for Liberty BASIC
              Carl Gundel .... Beginning Programming with Liberty BASIC

              Windows 7 Home Premium 64-bit RTM
              AMD Turion X2 RM-70 2GHz, 4GB RAM





              [Non-text portions of this message have been removed]
            • Stefan Pendl
              ... Your do loop will run constantly, which will cause one CPU core to be utilized by 100%. The Sleep API function will suspend the process from the CPU queue
              Message 6 of 8 , Aug 11, 2010
                > >
                > > do
                > > tcurrent = time$("milliseconds")
                > > loop until (tcurrent >= timeout)
                > >
                > > end sub
                > >
                >
                > '---code start (watch for line wraps)
                > sub Pause seconds
                > ' halt program execution for specified period
                > milliseconds = int(seconds * 1000)
                >
                > calldll #kernel32, "Sleep",_
                > milliseconds as ulong,_
                > result as void
                > end sub
                > '---code end
                >
                > Hi
                > Thanks again for your timersnip. I am normally using the
                > LB-timer. Is your time better than the LB-timer?
                > Now I have three timers to choose between. My state of mind
                > was more relaxed when I only knew about one timer.
                >
                > The reason I have to use timers is that three programs
                > should open after another and without timer they open almost
                > simultaneously
                > and interfear with each other. If I issue the sendkey-return
                > to early the return-key will not be actuated. I have a 4 year
                > old PC not very fast.
                > I wonder if I will have the same problems running on a faster PC.
                >
                > kind regards
                > Ingemar
                >

                Your do loop will run constantly, which will cause one CPU core to be utilized by 100%.

                The Sleep API function will suspend the process from the CPU queue for the given time, so your program will utilize 0% of one CPU
                core.
                Your program will not respond to any user-action during the delay.

                The TIMER method Rod mentions will use 0% of one CPU core too, but it will allow acting on user-actions, while in the WAIT state,
                which can be a problem in certain cases.

                ---

                The following decisions about the three ways to pause a program must be done:

                1) never use a loop to pause a program this is the worst thing to do

                2) if you want to wait till some time has passed and stop the user from
                being able to interact with your program, use the Sleep API function

                3) if you want to allow the user to interrupt the delay use the TIMER

                ---
                Stefan Pendl
                http://stefanpendl.runbasichosting.com/

                Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
                Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                Books at http://www.lulu.com/ and http://www.amazon.com/
                Alyce Watson ... APIs for Liberty BASIC
                Carl Gundel .... Beginning Programming with Liberty BASIC

                Windows 7 Home Premium 64-bit RTM
                AMD Turion X2 RM-70 2GHz, 4GB RAM
              • Ingemar Bjerle
                During this sendkey session a lot of information has been given. I have learned a lot thanks to all of you. I have included Stefans pause program in a
                Message 7 of 8 , Aug 12, 2010
                  During this sendkey session a lot of information has been given.
                  I have learned a lot thanks to all of you.
                  I have included Stefans pause program in a TypeString routine
                  that I am now using it in my program.
                  Ingemar

                  snippet
                  ' here at time zero a DOS program is openend and 2s later a TypeString call is made
                  call Pause 2000 ' if no pause is made the call will be issued before the DOS program is in focus.
                  call TypeString "en {13}" ' (en=english {13}=return)
                  end

                  sub TypeString message$
                  for i = 1 to len(message$)
                  t$ = mid$(message$,i,1)
                  if t$ <> "{" then
                  call keybdEvent asc(UPPER$(t$))
                  else
                  while RIGHT$(t$,1) <> "}"
                  i = i + 1
                  t$ = t$ + mid$(message$,i,1)
                  wend

                  t$ = mid$(t$,2,len(t$)-2)
                  call keybdEvent val(t$)
                  end if
                  next i
                  end sub

                  sub Pause milliseconds
                  calldll #kernel32, "Sleep",_
                  milliseconds as ulong,_
                  result as void
                  end sub

                  sub keybdEvent bVk
                  calldll #user32, "keybd_event",_
                  bVk as ushort,_
                  bScan as ushort,_
                  dwFlags as ulong,_
                  dwExtraInfo as ulong,_
                  result as void

                  calldll #user32, "keybd_event",_
                  bVk as ushort,_
                  bScan as ushort,_
                  _KEYEVENTF_KEYUP as ulong,_
                  dwExtraInfo as ulong,_
                  result as void
                  end sub



                  ----- Original Message -----
                  From: Stefan Pendl
                  To: libertybasic@yahoogroups.com
                  Sent: Thursday, August 12, 2010 8:14 AM
                  Subject: RE: [libertybasic] sendkeys



                  > >
                  > > do
                  > > tcurrent = time$("milliseconds")
                  > > loop until (tcurrent >= timeout)
                  > >
                  > > end sub
                  > >
                  >
                  > '---code start (watch for line wraps)
                  > sub Pause seconds
                  > ' halt program execution for specified period
                  > milliseconds = int(seconds * 1000)
                  >
                  > calldll #kernel32, "Sleep",_
                  > milliseconds as ulong,_
                  > result as void
                  > end sub
                  > '---code end
                  >
                  > Hi
                  > Thanks again for your timersnip. I am normally using the
                  > LB-timer. Is your time better than the LB-timer?
                  > Now I have three timers to choose between. My state of mind
                  > was more relaxed when I only knew about one timer.
                  >
                  > The reason I have to use timers is that three programs
                  > should open after another and without timer they open almost
                  > simultaneously
                  > and interfear with each other. If I issue the sendkey-return
                  > to early the return-key will not be actuated. I have a 4 year
                  > old PC not very fast.
                  > I wonder if I will have the same problems running on a faster PC.
                  >
                  > kind regards
                  > Ingemar
                  >

                  Your do loop will run constantly, which will cause one CPU core to be utilized by 100%.

                  The Sleep API function will suspend the process from the CPU queue for the given time, so your program will utilize 0% of one CPU
                  core.
                  Your program will not respond to any user-action during the delay.

                  The TIMER method Rod mentions will use 0% of one CPU core too, but it will allow acting on user-actions, while in the WAIT state,
                  which can be a problem in certain cases.

                  ---

                  The following decisions about the three ways to pause a program must be done:

                  1) never use a loop to pause a program this is the worst thing to do

                  2) if you want to wait till some time has passed and stop the user from
                  being able to interact with your program, use the Sleep API function

                  3) if you want to allow the user to interrupt the delay use the TIMER

                  ---
                  Stefan Pendl
                  http://stefanpendl.runbasichosting.com/



                  Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
                  Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

                  Books at http://www.lulu.com/ and http://www.amazon.com/
                  Alyce Watson ... APIs for Liberty BASIC
                  Carl Gundel .... Beginning Programming with Liberty BASIC

                  Windows 7 Home Premium 64-bit RTM
                  AMD Turion X2 RM-70 2GHz, 4GB RAM





                  [Non-text portions of this message have been removed]
                Your message has been successfully submitted and would be delivered to recipients shortly.