Jump to content

Update info on Koda GUI on key press


Dxnny
 Share

Recommended Posts

Is there a way to make it so when I press a key down, it will display some information on the Koda GUI I already have made.

So when I press the K key it will pop on the GUI saying "Category B is now enabled", then would disappear after 5 seconds or so.

 

Link to comment
Share on other sites

Something like this?

; update label examnple

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 438, 190, 192, 124)
$Button1 = GUICtrlCreateButton("Press Me", 120, 96, 185, 33)
$Label1 = GUICtrlCreateLabel("Sow this label on key pree but only for three seconds", 96, 64, 253, 17)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        case $Button1
            GUICtrlSetState($Label1,$GUI_SHOW)
            sleep(3000)
            GUICtrlSetState($Label1,$GUI_HIDE)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

19 minutes ago, Jfish said:

Something like this?

; update label examnple

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 438, 190, 192, 124)
$Button1 = GUICtrlCreateButton("Press Me", 120, 96, 185, 33)
$Label1 = GUICtrlCreateLabel("Sow this label on key pree but only for three seconds", 96, 64, 253, 17)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        case $Button1
            GUICtrlSetState($Label1,$GUI_SHOW)
            sleep(3000)
            GUICtrlSetState($Label1,$GUI_HIDE)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

I don't want to have to press a button on a GUI, I want to press a key down, like the letter K. Is that possible?

Link to comment
Share on other sites

merging the two concepts ... something like this?

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

GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'))
GUIRegisterMsg($WM_KEYDOWN, 'WM_KEYDOWN')
GUISetState(@SW_SHOW)
$Label1 = GUICtrlCreateLabel("Sow this label on D key press but only for three seconds", 25, 50, 350, 25)
GUICtrlSetState(-1, $GUI_HIDE)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE


Func WM_KEYDOWN($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    ConsoleWrite(_WinAPI_GetKeyNameText($lParam) & @CRLF)
    if _WinAPI_GetKeyNameText($lParam) = "D" then
        GUICtrlSetState($Label1,$GUI_SHOW)
        sleep(3000)
        GUICtrlSetState($Label1,$GUI_HIDE)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_KEYDOWN

 

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

It is not a good idea to hold few seconds a notification.  As you can read in help file :

Warning: blocking of running user functions which executes window messages with commands such as "MsgBox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!

Also WM_KEYDOWN will hardly be useful if you got some controls in the GUI.

Using _IsPressed function or having a keyboard callback would be better (depending if you want the key to go thru or be held)...

Link to comment
Share on other sites

This is an example with _IsPressed :

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

GUICreate('Test')
GUICtrlCreateInput ("", 100,100,100,25)
GUICtrlCreateButton ("Test", 150,150,80,25)
GUISetState(@SW_SHOW)

Local $bTool = False

Do
  If _IsPressed ("4B") Then ; K key
    ToolTip ("Category B is now enabled")
    $bTool = True
    $hTime = TimerInit ()
  EndIf
  if $bTool and TimerDiff ($hTime) > 5000 Then ToolTip ("")
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Key goes thru to the GUI...

 

Here another example where key is captured :

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

GUICreate('Test')
GUICtrlCreateInput ("", 100,100,100,25)
$idK1 = GUICtrlCreateDummy ()

Local $aAccelKeys[1][2] = [["k", $idK1]]
GUISetAccelerators($aAccelKeys)
GUICtrlCreateButton ("Test", 150,150,80,25)

GUISetState(@SW_SHOW)

Local $bTool = False

While True
  Switch GUIGetMsg ()
    Case $GUI_EVENT_CLOSE
      ExitLoop
    Case $idK1
      ToolTip ("Category B is now enabled")
      $bTool = True
      $hTime = TimerInit ()
  EndSwitch
  if $bTool and TimerDiff ($hTime) > 5000 Then ToolTip ("")
WEnd

 

Edited by Nine
Link to comment
Share on other sites

16 hours ago, Nine said:

This is an example with _IsPressed :

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

GUICreate('Test')
GUICtrlCreateInput ("", 100,100,100,25)
GUICtrlCreateButton ("Test", 150,150,80,25)
GUISetState(@SW_SHOW)

Local $bTool = False

Do
  If _IsPressed ("4B") Then ; K key
    ToolTip ("Category B is now enabled")
    $bTool = True
    $hTime = TimerInit ()
  EndIf
  if $bTool and TimerDiff ($hTime) > 5000 Then ToolTip ("")
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Key goes thru to the GUI...

 

Here another example where key is captured :

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

GUICreate('Test')
GUICtrlCreateInput ("", 100,100,100,25)
$idK1 = GUICtrlCreateDummy ()

Local $aAccelKeys[1][2] = [["k", $idK1]]
GUISetAccelerators($aAccelKeys)
GUICtrlCreateButton ("Test", 150,150,80,25)

GUISetState(@SW_SHOW)

Local $bTool = False

While True
  Switch GUIGetMsg ()
    Case $GUI_EVENT_CLOSE
      ExitLoop
    Case $idK1
      ToolTip ("Category B is now enabled")
      $bTool = True
      $hTime = TimerInit ()
  EndSwitch
  if $bTool and TimerDiff ($hTime) > 5000 Then ToolTip ("")
WEnd

 

All I essentially want is all the console information to pop up on a GUI instead of in SciTE console.

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

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...