Jump to content

_ispressed Function Error


Recommended Posts

i am writing a code for a beep keyboard, though there is really no "notes" per say, when you push the keyborad buttons on your actual keyboard, they beep. however, my "ispressed function is giving me this error wen i try to do the "j" key

my code for j key:

If _IsPressed(4A) then;j
   $default = 1
   $freq = 2700
   Beep($freq, $delay)
Endif

the error message i get

//////////////////////////////////////////////////////////////////////

Line 150: If _IsPressed(4A) then;j

Line 150: If _IsPressed(^ERROR

Error:Unable to Parse line.

/////////////////////////////////////////////////////////////////////

Anyone know why?
Link to comment
Share on other sites

your code is not correct

1

you need "" around the "4A"

2

Beep($freq, $default)

or

Beep($freq, $delay)

#Include <Misc.au3>


While 1
    
If _IsPressed("4A") then;j
   $default = 1
   $freq = 2700
   Beep($freq, $default)
Endif

WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

you need quotes around 4A

valuater beat me to it

Edited by RazerM
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

HI,

take a look at and you'll see what you are missing.

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep ( 250 )
    If _IsPressed("23", $dll) Then
        MsgBox(0,"_IsPressed", "End Key Pressed")
        ExitLoop
    EndIf
WEnd
DllClose($dll)

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

not true either... see the last post by meger ( the preferred way per help anyways )

8)

Weird, then why does this code work?

$delay=500

If _IsPressed(47) then;g
   $default = 1
   $freq = 2500
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(48) then;h
   $default = 1
   $freq = 2600
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(49) then;i
   $default = 1
   $freq = 1800
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4A") then;j
   $default = 1
   $freq = 2700
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4B") then;k
   $default = 1
   $freq = 2800
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4C") then;l
   $default = 1
   $freq = 2900
   Beep($freq, $delay)
Endif
Link to comment
Share on other sites

the preferred way per help anyways

Oh ok, missed that

I got one more question

right now, i have delay just set to 500 at the top of my script, how could i make it be as long as a key is pressed, and is there a way to do it without re-writing my entire code? If not, here is my whole code.

hotkeyset('{esc}', 'halt')
func halt()
    exit
endFunc
;----------------------Variables------------------------------------
#cs
Total Keys:
36
#ce
Global $freq
Global $delay=500
;---------------------------Setting delay------------------------------
;----------------------------Default-----------------------------------
Run(notepad.exe)
;---------------------------_IsPressed Function----------------------------
Func _IsPressed($hexKey)
; $hexKey must be the value of one of the keys.
; _IsPressed will return 0 if the key is not pressed, 1 if it is.
; $hexKey should entered as a string, don't forget the quotes!
; (yeah, layer. This is for you)
 
  Local $aR, $bO
 
  $hexKey = '0x' & $hexKey
  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
  If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
     $bO = 1
  Else
     $bO = 0
  EndIf
 
  Return $bO
EndFunc ;==>_IsPressed
;----------------------------What The Whole script is------------------
While 1
WinActivate(Untitled - NotePad)
;~~~Numbers
If _IsPressed(30) then;0
   $freq = 1000
   Beep($freq, $delay)
Endif
If _IsPressed(31) then;1
   $freq = 100
   Beep($freq, $delay)
Endif
If _IsPressed(32) then;2
   $freq = 200
   Beep($freq, $delay)
Endif
If _IsPressed(33) then;3
   $freq = 300
   Beep($freq, $delay)
Endif
If _IsPressed(34) then;4
   $freq = 400
   Beep($freq, $delay)
Endif
If _IsPressed(35) then;5
   $freq = 500
   Beep($freq, $delay)
Endif
If _IsPressed(36) then;6
   $freq = 600
   Beep($freq, $delay)
Endif
If _IsPressed(37) then;7
   $freq = 700
   Beep($freq, $delay)
Endif
If _IsPressed(38) then;8
   $freq = 800
   Beep($freq, $delay)
Endif
If _IsPressed(39) then;9
   $freq = 900
   Beep($freq, $delay)
Endif
;~~~Letters----------------------------------

If _IsPressed(41) then;a
   $freq = 2100
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(42) then;b
   $freq = 3400
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(43) then;c
   $freq = 3200
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(44) then;d
   $freq = 2300
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(45) then;e
   $freq = 1300
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(46) then;f
   $freq = 2400
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(47) then;g
   $freq = 2500
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(48) then;h
   $freq = 2600
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(49) then;i
   $freq = 1800
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4A") then;j
   $freq = 2700
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4B") then;k
   $freq = 2800
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4C") then;l
   $freq = 2900
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4D") then;m
   $freq = 3600
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4E") then;n
   $freq = 3500
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("4F") then;o
   $default = 1
   $freq = 1900
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(50) then;p
   $freq = 2000
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(51) then;q
   $freq = 1100
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(52) then;r
   $freq = 1400
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(53) then;s
   $freq = 2200
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(54) then;t
   $freq = 1500
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(55) then;u
   $freq = 1700
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(56) then;v
   $freq = 3300
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(57) then;w
   $freq = 1200
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(58) then;x
   $freq = 3100
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed(59) then;y
   $freq = 1600
   Beep($freq, $delay)
Endif
;~~~~~~
If _IsPressed("5A") then;z
   $freq = 3000
   Beep($freq, $delay)
Endif
;~~~~~~

Wend

Note Defaults werent doing anything

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