Jump to content

Recommended Posts

Posted

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.

 

Posted

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

Posted
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?

Posted

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

Posted

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

Posted (edited)

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

Posted

That's not doing what I need though, I need it so when I press a key on my keyboard it will show up on the GUI, not when I press a button on the GUI itself.

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
×
×
  • Create New...